Say I have an array myArray
of some length N
. I want to loop N
th time. In pure Javascript, that would be:
for (var i = 0; i < myArray.length; i++) {}
Is there a way to also do this in UnderscoreJS? I know I can use _.each
in the following way:
_.each(myArray, function(a) {
});
but I don't particularly want to loop through the entries. There is no reason why i want to do this. This is purely a thought experiment and I was just wondering if there is a way of doing this!
_.each
? Doesn't it call the functionN
times?_.each
. It does runN
times. But I was just wondering if I could create the exact same thing as thefor
loop in Javascript (i.e. just loop with the index, not the actual item)._.times(myArray.length, function() {...})
?