迭代js / node10中的对象数组并访问每个项目的属性
我正在尝试使用带有w / node.js 10的javascript遍历如下所示的对象数组。
我尝试了以下操作,但它说这是不可迭代的:
const persons = [
{ id: 1, name: 'Alice', age: null },
{ id: 2, name: 'Mike', age: 52 },
{ id: 3, name: 'Carol', age: 50 }
]
for(let person of persons) {
console.log(person.id);
}
回答如下:for(let person of persons) {
console.log(person.id); --> should be person.id
}
迭代js / node10中的对象数组并访问每个项目的属性
我正在尝试使用带有w / node.js 10的javascript遍历如下所示的对象数组。
我尝试了以下操作,但它说这是不可迭代的:
const persons = [
{ id: 1, name: 'Alice', age: null },
{ id: 2, name: 'Mike', age: 52 },
{ id: 3, name: 'Carol', age: 50 }
]
for(let person of persons) {
console.log(person.id);
}
回答如下:for(let person of persons) {
console.log(person.id); --> should be person.id
}
与本文相关的文章
评论列表 (0)
- 暂无评论