I have the following code snippet in JS
names = [{name: "A"},
{name: "B"},
{name: "C"},
{name: "D"}];
var returnNames = function(item, index) {
var p = names[index].nome;
return p;
}
names.forEach(returnNames);
I would like to print all the names according to the index but when I call the function it doesn't return any value What am I doing wrong?