+1 vote
7 views
by

I have JavaScript object array with the following structure:

objArray = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ];

1 Answer

0 votes
by
selected by
 
Best answer
Here is a shorter way of achieving it:

let result = objArray.map(a => a.foo);
OR

let result = objArray.map(({ foo }) => foo)
You can also check Array.prototype.map().
Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
...