How to do it more efficiently?
Posted
by David Maricone
on Stack Overflow
See other posts from Stack Overflow
or by David Maricone
Published on 2010-06-04T05:29:51Z
Indexed on
2010/06/04
6:09 UTC
Read the original article
Hit count: 221
Let's imagine we should get some data...
var data = [];
//some code omitted that might fill in the data (though might not)
Then we need to do something with the data. And my question is how to do it more effectively. Like so?:
if (data.length) {
for (var i = 0; i < data.length; i++) {
//iterate over the data and do something to it
}
}
Or just like so?:
for (var i = 0; i < data.length; i++) {
//iterate over the data and do something to it
}
The point is whether to check the length before iterating or not?
© Stack Overflow or respective owner