迭代对象(Iterable objects, 如 maps, arrays, strings)可以用迭代器的next() 方法进行迭代

内置的可迭代对象

使用迭代器的语法

for...of , 迭代器专用for 循环

for (const value of iterable) { ... }

Destructuring of Arrays, 解构语法

const array = ['a', 'b', 'c', 'd', 'e'];
const [first, ,third, ,last] = array;

相当于:

const array = ['a', 'b', 'c', 'd', 'e'];
const iterator = array[Symbol.iterator]();
const first = iterator.next().value
iterator.next().value // Since it was skipped, so it's not assigned
const third = iterator.next().value
iterator.next().value // Since it was skipped, so it's not assigned
const last = iterator.next().value

The spread operator (…), 三点操作符, 扩散操作符

const obja = {a:"astr", b:"bstr"}
const objb = { ...obja }
objb // {a: "astr", b: "bstr"}
const array = ['a', 'b', 'c', 'd', 'e'];
const newArray = [1, ...array, 2, 3];

//相当于👇

const array = ['a', 'b', 'c', 'd', 'e'];
const iterator = array[Symbol.iterator]();
const newArray = [1];
for (let nextValue = iterator.next(); nextValue.done !== true; nextValue = iterator.next()) {
  newArray.push(nextValue.value);
}
newArray.push(2)
newArray.push(3)

一个数据结构只要具有Symbol.iterator 属性, 就是“可遍历的”(iterable)