What I’m given in my homework is and JS object that looks like:
myObj =
{name:eric, location:belgium, age:24},
{name:jools, location:holland, age26},
{name:mike, location:usa, age:30},
the idea is that somehow if i need to target ‘location’ holland i need to be able to treat all this like an arary so I can work with indexes (at least that’s what I think). I Can’t find any example anywhere where people work with this been searching for a bit on ‘js object’.
The actual challenge is to be able to put the different values of the ‘name’ property as innerHTML(or some method that does something similar) of new option elements inside a given select element probably through a loop. Since this is homework, I don’t need the actual code for that but a clue on where I can learn more about how these JS object property array type of things work would be nice.
thanks a lot!
Your JavaScript snippet is invalid, something makes me think there was a copy-and-paste error. The answer changes significantly depending on what the code actually looks like.
If it looks like this:
…then you’re dealing with an array of objects, where each object has the properties
nameandlocation. You can loop through them using a standardforloop with an index variable, counting from0tomyObj.length - 1(inclusive), and access the properties of each object viamyObj[index].nameandmyObj[index].location.