1. var a = ['A', 'B', 'C']
    2. //iteraable内置的forEach方法它接受一个函数每次迭代就自动回调该函数以Array为例
    3. a.forEach(function (element, index, array) {
    4. //element:指向当前元素的数值
    5. //index:指向当前索引
    6. //指向Array对象本身
    7. console.log(element + ',index=' + index)
    8. })
    1. var s = new Set(['A', 'B', 'C'])
    2. s.forEach(function (element, sameElement, set) {
    3. console.log(element)
    4. });
    1. var m = new Map([[1, 'x'], [2, 'y'], [3, 'z']])
    2. m.forEach(function (value, key, map) {
    3. console.log(value)
    4. })
    1. // 斐波那契数列
    2. 'use strict'
    3. function* fib(max) {
    4. var t,
    5. a = 0,
    6. b = 1,
    7. n = 0;
    8. while (n < max) {
    9. yield a;
    10. [a, b] = [b, a + b];
    11. n++;
    12. }
    13. return;
    14. }
    15. for (const x of fib(10)) {
    16. console.log(x)
    17. }