Given an javascript object:
myList = {
"1": "Winter",
"2": "Spring",
"3": "Summer",
"4": "Fall"
}
and supposing that the variable season
contains the first item, how do I access "1" and/or "Winter"?
Edit: myList['1'] is not the answer I am looking for because I want to access either "1" or "Winter" from the season
variable. It is not a duplicate of the marked question.
Instead, I want to do something like:
for(var season in myList) {
foo( season.key ); // should be "1" on the first pass
bar( sesson.val ); // should be "Winter" on the first pass
}
I've seen somewhere that you can do an inner loop to get the key and value. Is there some other way aside from doing that?