迭代实现了iterable协议的对象。
示例:
const names = ["Kent Beck", "Erich Gamma", "James Gosling", "Doug Lea", "Bob Lee"];
for (let name of names) {
console.log(name);
}
示例:
const bytes = new Uint8Array([0x00, 0xff]);
for (let byte of bytes) {
console.log(byte);
}
示例:
(function() {
for (let argument of arguments) {
console.log(argument);
}
})(1, 2, 3);
示例:
const base16 = '0123456789abcdef';
for (let char of base16) {
console.log(char);
}
示例:
const set = new Set([1, 1, 2, 2, 3, 3]);
for (let element of set) {
console.log(element);
}
示例:
const map = new Map([['a', 1], ['b', 2], ['c', 3]]);
for (let {key, value} of map) {
console.log('%s:%s', key, value);
}