I orginally was going to ask a question on why it wasn't working. But as I commented the code I realized that I could access the text array style and item
was giving me the index. It took me a while to find this as the solution, however I would have much rather used item.text
in the for loop. Is this [my posted answer] the valid way to loop through JSON objects in Javascript?
|
|||
|
There's no such thing as a JSON object - once you've parsed your JSON (which is a string) you end up with simply an object. Or an array. Anyway, to loop through an array of objects, use a traditional In your specific case, if
You can also, arguably, make the code a bit neater by keeping a reference directly to the array rather than accessing it via the whole
In your answer - which really should've been posted as part of the question - because you are using a
That is, declare a variable called |
|||||||||||||
|
|
|||||||||||||||||||||
|