for-in/for-of

for-in:key,适用于object
for-of:value,用于Array,string,set,map

let obj = {
name: 'wuxiaodi',
age: 18,
};
for (let i in obj) {
console.log(i)//name age
}


for (let i of arr) {
console.log(i)//wuxiaodi 18
}

 

posted @ 2021-12-08 09:07  lisa2544  阅读(22)  评论(0编辑  收藏  举报