I am a very beginner with Javascript and I'm working on a question from my Mentor that I'm totally stuck on:
Create a function that accepts one parameter. This parameter will be an array of objects. Each object will have 1 property name. The function should return a new array that is populated with the name properties from the objects.
Example
namesFunction([{name: 'Tacos'},{name: 'Burritos'},{name: 'Enchiladas'}]);
//returns ['Tacos', 'Burritos', 'Enchiladas']
I do not know how to make a for loop that will iterate over any array put into the function parameters. I've only done ones that have defined arrays.
This is what I have:
function namesFunction(){
var arr = [];
for (i = 0; i < arr.length; i++){
console.log(arr[i].name);
}
}
namesFunction([{name: 'Tacos'},{name: 'Burritos'},{name: 'Enchiladas'}]);
Any help is appreciated! Thank you!