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