i tried to loop over an array nested in an object and log it to my console but the console keeps logging out "undefined".
let dogspace = {
name: "rusty",
friends: ["ruby", "frun", "geo"],
print: function (){
this.friends.forEach(friend => {
return friend
});
}
}
You are not printing anything in the for each. You are just returning stuff. Which does nothing really in forEach.
Try this:
let dogspace = {
name: "rusty",
friends: ["ruby", "frun", "geo"],
print: function() {
this.friends.forEach(friend => {
console.log(friend);
});
}}
dogspace.print();