How to do it more efficiently?
- by David Maricone
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?