Iterable
ES6新特性
遍历数组
// for of 打印值 , for in 打印下标
var arr = [4,5,6]
for (const number of arr) {console.log(number)
}
遍历Map
var map = new Map([['whl',100],['ht',110],['other',0]])
for (let x of map) {console.log(x)console.log(x[0])console.log(x[1])
}
遍历Set
var set = new Set([4,5,6])
for(let x of set) {console.log(x)
}
一个漏洞
var arr = [4,5,6]
arr.name = "43"
console.log(arr)for (let x in arr) {console.log(x)
}console.log("==========")
for (let number of arr) {console.log(number)
}
for of 不会打印出这个错误,但是 for in 会打印出
https://www.bilibili.com/video/BV1JJ41177di?p=11