0
Getting Properties Of All Objects In Array
I was wondering how I can get the properties of objects that are in an array. I wanted to go through the array in a loop and output their properties, but the browser just outputs undefined. Iâm assuming this is because it doesnât know they are all of the same class and therefore all have those properties, so how can I tell it this?
3 Answers
+ 1
I think I just figured it out. Iâm used to java where you can use a for each (for/in) for going through arrays, but from what I read, it sounds like in javascript, they only work for looping through object properties. Thanks for your help though!
0
As long as all the objects in the class actually do have that property, it shouldnât be an issue. Can you share the code youâre having issues with?
0
The part that keeps showing undefined is
for(var x in lettersInHand)
document.getElementById(âhandâ). innerHTML+=â<span>â+x.character+â<spanâ;
I put a print earlier in the method and it showed everything in the array as being a Letter, so I donât know why they donât seem to have a character property in the loop