I have an array like this
array = [
{
id: 1,
name: 'Apple',
color: 'red
},
{
id: 2,
name: 'Orange',
color: 'orange'
},
{
id: 3,
name: 'Banana',
color:'yellow'
},
{
id: 4,
name: 'Malta',
color:'orange'
}
];
and I just want to get "id" attribute from this array like this
array = [
{
id: 1,
},
{
id: 2,
},
{
id: 3,
},
{
id: 4,
}
];
What should be the method to handle this situation. I tried filter method , map method but it didn't work
mapshould do the job just fine here.mapis the correct way. However, please show your code; note that "it didn't work" is a useless description (if it worked, you probably wouldn't be here, asking), and a good description of how, precisely it failed to work (with example input, example output and how it differs from the desired output) is much, much more useful.maplikearray.map(x => x.id)