Extract list of values from an array of objects to an array based on a key in JavaScript.

There may be a situation where you want to extract the list of values of a specific key from an objects to an array.

Method 1:

In one way, we can use both for loop and Array.push() method and achieve it.

For example, we have an Array of objects as below

we can extract the values as shown below

Method 2:

The simple and easy way is using map function as below

Here we’ve to assign the map function to a variable. If we don’t assign to a variable, then the whole array object will be printed as it is.

Hope this is useful😋

Originally published at

--

--

Artist and Writer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store