我如何到达数组内的对象,mylist = [{整个:'thing',代码:'a'},{整个:'thing2',代码:'b'}]

时间:2018-12-29 16:59:38

标签: javascript

我只能得到无法到达对象内部的整个对象数组

list = [{whole: 'thing', code: 'a'}, {whole: 'things', code: 'b'}]

console.log(list)将列表作为对象,其中包含键值对。但是我需要达到整体和代码的价值

1 个答案:

答案 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));