for in 和 for of的区别

for in 和 for of的区别是:in 是遍历对象,of是遍历值

let set = new Set(['red', 'green', 'blue']);
for (let x of set) {
  console.log(x);
}
red
green
blue
let set = new Set(['red', 'green', 'blue']);
for (let x in set) {
  console.log(x);
}
undefined

 

posted @ 2021-11-19 17:40  霓裳依旧  阅读(229)  评论(0编辑  收藏  举报