1.for ... in是遍历数组、对象的key
let arr = [1, 2, 3];
for (let i in arr) {
console.log(i) // 0 1 2
}
let obj = {
name: 'zhangsan',
age: 18,
};
for (let i in obj) {
console.log(i) //name value
}
2.for ... of是遍历数组value
let obj = [1,2,3]
for (let i of obj) {
console.log(i) //zhangsan 18
}
网友评论