从带有对象的数组中提取子参数

时间:2020-09-03 12:16:04

标签: javascript

我有下一个数组:

let someArr = [
{param:{name: 'bla'}},
{param:{name: 'blu'}}
];

如何不使用'param'来获得数组?

[{name: 'bla'},{name: 'blu'}]

2 个答案:

答案 0 :(得分:1)

let someArr = [
{param:{name: 'bla'}},
{param:{name: 'blu'}}
];

const result = someArr.map(el => el.param);
console.log(result);

答案 1 :(得分:0)

let newArray = someArr.map(item => {
  return item.param;
});