Loop through set of elements without the .length method
Loop through set of elements without the .length method
by Nirvanachain
HTML
<!-- Helpful URL:
http://stackoverflow.com/questions/157260/whats-the-best-way-to-loop-through-a-set-of-elements-in-javascript
-->
JavaScript
var list = [{a:1,b:2}, {a:3,b:5}, {a:8,b:2}, {a:4,b:1}, {a:0,b:8}];
for (var i=0, item; item = list[i]; i++) {
// Look no need to do list[i] in the body of the loop
console.log("Looping: index " + i + "item" + item + " item.a = " + item.a + " item.b = " + item.b);
}