I have heard that the for(){...}
loop in JavaScript is passé and should not be used in favor of other, clearer alternatives. JSLint goes so far as to throw an error when it encounters one (unless you override it, of course). I understand using Array.prototype.forEach()
when the situation allows, but in this instance what alternative could I use that would be "clearer"?
var number = 5;
for (var i=0; i <= number; i++){
log("somestring" + i);
}
In C#
I would use a foreach(){...}
over Enumerable.Range(0, 5)
- but I know of no such alternative in JavaScript. I could create an array of digits 0...5 but that seems like going the long way for no gain.
Edit 1
I am not looking for an alternative plugin to implement this like lodash or jQuery, and my question really isn't about "why does JSLint...". What native JavaScript alternative would I use?