JS Symbol.Iterator 迭代器
JS Symbol.Iterator 迭代器
简洁遍历迭代器
const arr = [1, 2, 3, 4, 5, 6]
// 执行一个迭代器 赋值给 iterator 变量
const iterator = arr[Symbol.iterator]();
// 使用 while 循环 先执行一次
let next = iterator.next()
while (!next.done) {
console.log(next.value)
原创
2021-05-22 15:42:09 ·
576 阅读 ·
0 评论