我只能得到无法到达对象内部的整个对象数组
list = [{whole: 'thing', code: 'a'}, {whole: 'things', code: 'b'}]
console.log(list)将列表作为对象,其中包含键值对。但是我需要达到整体和代码的价值
答案 0 :(得分:2)
let list = [
{ whole: 'thing', code: 'a' },
{ whole: 'things', code: 'b'},
];
// access specific whole of object at index
console.log(list[0].whole);
console.log(list[1].whole);
// print each whole of object in list
list.forEach(({ whole }) => console.log(whole));