减少javascript中的对象数组

时间:2018-04-20 15:22:43

标签: javascript arrays ecmascript-6

如何减少此类型的对象数组:

.settings

我需要使用这些值获得一个新数组:

[
 {id: 1, name: 'jhon', lastname: 'doe', age: 30},
 {id: 2, name: 'max', lastname: 'wall', age: 20},
 {id: 3, name: 'fer', lastname: 'baneg', age: 15}
]

1 个答案:

答案 0 :(得分:2)

您可以使用map()方法进行ES6参数解构。



const data = [{id: 1, name: 'jhon', lastname: 'doe', age: 30},{id: 2, name: 'max', lastname: 'wall', age: 20},{id: 3, name: 'fer', lastname: 'baneg', age: 15}]

const result = data.map(({id, name}) => ({id, name}))
console.log(result)