Extract Given Property Values from Objects as Array

Extract Given Property Values from Objects as Array


In this example, you will learn to write a JavaScript program that will extract the value of a property as an array from an array of objects.

To understand this example, you should have the knowledge of the following JavaScript programming topics:

JavaScript Array push()

JavaScript Array map()

JavaScript Objects


Example 1: Extract Value Using map()



In the above program, the property's value of key a is extracted from each object of an array.


The map() method is used to iterate through all the elements of an array and extract property values of key a.


Note: You could also use a regular function instead of an arrow function.



Example 2: Extract Value Using for Loop



In the above program, the property value of key a is extracted from each object of an array.


Initially, the extracted value array is empty.

The for loop is used to iterate through all the elements of an array.

During each iteration, the value of property a is pushed to the extracted value array. 

Post a Comment

Previous Post Next Post