如何减少此类型的对象数组:
.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}
]
答案 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)