1、
let d = {'a': 1, 'b': 2, 'c': 3}
for (const key in d){
console.log(key, d[key])
}
2、
let d = {'a': 1, 'b': 2, 'c': 3}
for (const [key, value] of Object.entries(d)){
console.log(key,value)
}
文章讲述了在JavaScript中使用for-in和for-of循环遍历对象d的不同方法,分别展示了如何打印键和对应的值。
1、
let d = {'a': 1, 'b': 2, 'c': 3}
for (const key in d){
console.log(key, d[key])
}
2、
let d = {'a': 1, 'b': 2, 'c': 3}
for (const [key, value] of Object.entries(d)){
console.log(key,value)
}
782

被折叠的 条评论
为什么被折叠?