+ 1

Access array properties in JS?

Hello, i am currently practicing Javascript and i am testing the forEach method and it works fine on simple arrays ex: let colors = [ 'red', 'green', 'blue']; colors.forEach(say); function say(color){document.write("The color" + color + "is nice")} That's all well and good, BUT. if im working with a more complex array, like this one... ex: let armory = [ {class: "weapon", name: "Sword", price: 150}, {class: "weapon", name: "Trident", price: 300}, {class: "armor", name: "Shield", price: 100}, {class: "weapon", name: "Katana", price: 450}, {class: "armor", name: "Brigadine", price: 300} ] ...and i want to say the names of every item inside, and i use forEach, all i get is "object object" ...how to access specific array properties using forEach? is there any other way? (without using map or filter) Thanks for your attention.

17th Apr 2019, 2:57 PM
Mariano Leonel Roura
1 Answer
+ 4
armory.forEach(say); function say(a) { document.write(a.name); }
17th Apr 2019, 4:06 PM
CalviŐ˛
CalviŐ˛ - avatar