最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

迭代jsnode10中的对象数组并访问每个项目的属性

IT培训 admin 8浏览 0评论

迭代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)

  1. 暂无评论