js loop over array of objects extract value 1

js loop over array of objects extract value

var myArr = [{name: 'rich', secondName: 'james'}, {name: 'brian', secondName: 'chris'}];

var mySecondArr = myArr.map(x => x.name);
console.log(mySecondArr);

Here is what the above code is Doing:
1. We have an array of objects.
2. We use the map function to iterate through the array.
3. We use the arrow function to return the name property of each object.
4. We store the result in a new array.

Similar Posts