【发布时间】:2021-11-16 07:52:05
【问题描述】:
我有一个对象列表。每个对象都有一个属性,它是一个元素列表:
{ name : 'Club 01'
, id : 1
, form : 45
, points : 0
, tactics : 'neutral'
, played : 0
, gameset : 0
, playedWith : [ 8, 1, 2, 3 ]
}
我想通过列表和控制台记录所有现有元素:
for (let a = 0; a<clubs.width; a++) {
for (let b = 0; b<clubs[a].playedWith.width; b++) {
console.log(clubs[a].playedWith[b]);
}
}
当我为一件物品做这件事时,这很有效。但是,当我使用循环作为 aboce 时,这让我想到了
undefined
我的代码有什么问题?如何控制台记录 playWith 属性中的所有项目?
【问题讨论】:
-
为什么是
clubs[a].playedWith.WIDTH?不是.length?
标签: javascript arrays loops properties