首页 > 解决方案 > From an array of objects, extract value of two properties into an array

问题描述

Consider a JavaScript object array with the following structure: objArray = [ { foo: 1, bar: 2, anotherfoo:5}, { foo: 3, bar: 4, anotherfoo: 8}];

How can I use map to extract foo and anotherfoo into a new array. Possible duplicate of

标签: javascriptarrays

解决方案


arr.map(({foo, anotherfoo}) => ({foo, anotherfoo}))

推荐阅读