I have this array of objects:var array = [{name: "Tom", id: 123}, {name: "chris", id: 1234}, {name: "Simon", id: 111}];
I want to iterate through the 3 objects in the array and extract the name of each one, and then push that name into a new array.
This is what I thought would work:
var array = [{name: "Tom", id: 123}, {name: "chris", id: 1234}, {name: "Simon", id: 111}];
var newArrayOfNames = [];
Object.values(array).forEach(function(name){
newArrayOfNames.push(name);
});
console.log(newArrayOfNames);
newArrayOfNames.push(name);tonewArrayOfNames.push(name.name);var names = array.map(o => o.name).Object.values(array)is not supported in my test environment. Refer to Uncaught TypeError: Object.values is not a function JavaScript