I am trying to return all the names from an object of arrays in to an new array just containing the names, but its not working, the if statement covers the issue of dealing with an empty array being passed here is the object, any suggestions much appreciated:-
const obj = [{
name: "Mitch",
age: 27,
language: "Javascript"
},
{
name: "Ant",
age: 28,
language: "Java"
},
{
name: "Natalia",
age: 29,
language: "C"
},
{
name: "Foluso",
age: 26,
language: "Ruby"
}
];
let newArray = [];
for (let i = 0; i <= obj.length; i++) {
newArray.push(obj.name);
if (obj => obj.length = 0) {
newArray = [];
}
}
return newArray;
}