Consider the input array below:
const initialArray = [{name: 'john', age: 12, height: 178, likes: 'music'},
{name: 'mike', age: 22, height: 181, likes: 'sport'},
{name: 'anna', age: 18, height: 175, likes: 'sleep'},
{name: 'paul', age: 24, height: 170, likes: 'drink'}
];
To create a new array of objects with specific properties such as name
and height
, you can achieve the following result:
result = [{name: 'john', height: 178},
{name: 'mike', height: 181},
{name: 'anna', height: 175},
{name: 'paul', height: 170}
];
An attempt using map
was made but it seems to have an issue:
const result = initialArray.map((a) => {
a.name, a.height
});