假设我有一个像这样的数组:
arrayOfObject = [{item: {this: is, that: is}}, {item2: {this: is, that: is}}]
我正在尝试访问 item 和 item2,而不必使用 0/1 索引。我希望能够说 arrayOfObjects[item] 进入该对象。这可能吗?
最佳答案
您可以使用Array.find。
arrayOfObject = [{
item: {
this: 'is',
that: 'is'
}
}, {
item2: {
this: 'is',
that: 'is'
}
}]
console.log(arrayOfObject.find(ob => ob['item']));
console.log(arrayOfObject.find(ob => ob['item2']));
关于javascript - 如何进入数组中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52102180/