Extract certain properties from all objects in array

Use object destructuring to get the properties, and generate a new object using shorthand property names:

const dummyArray = [{ "att20": "att20", "att30": "att30", "att70": "att70", "att80": "att80"}, { "att20": "att20", "att30": "att30", "att70": "att70", "att80": "att80"}];

const result = dummyArray.map(({ att20, att30, att70, att80 }) => ({
  att20, 
  att30, 
  att70, 
  att80
}));

console.log(result);

Leave a Comment