How might I iterate over objects inside an array in proper notation?

jafik2005

New Member
I read through Javascript The Good Parts, and learned that using \[code\]for (i in blah) {}\[/code\] is bad notation, but the problem is, I'm using \[code\]Node.js\[/code\] and the database I'm using \[code\]MongoDB\[/code\] returns all its queries as \[code\]objects\[/code\] which is fine. Right now I have an ajax query that pulls all information from a table, and I want to do things with each value. But what the database is returning is an array (with a random size depending on whats in the database) that contains objects, for clarity sake I'll give you an example:\[code\][ { 'a': 'value of a', 'b': 'value of b', 'c': 'value of c' }, { 'a': 'value of a', 'b': 'value of b', 'c': 'value of c' }]\[/code\]How can I iterate through each thing so that I can assign variables from each one this is what I have worked up:\[code\] for (var i = 0; i < data.success.length; i += 1) { for(x in data.success) { console.log(x); } }\[/code\]I'm just worried that the bad notation will bite me in the end, I read that the \[code\](blah in blah)\[/code\] notation doesn't always return results in order. Which this HAS to be in order. Hope I made myself clear, thanks.I need to get the values, not the name of the variable in the object.
 
Top