Search code examples
javascriptloopsinteger

Loop in javascript over integers


I am still newbie in javascript

I am looking for a simple loop in javascript with iteration over integers where I am not interested in the item.

in python it looks like this: for i in range(10)

in ruby: (1..10).each

the simplest example in javascript I found is this:

_.each(Array.apply(null, new Array(10)).map(Number.prototype.valueOf,0)

Do you familiar with simpler example?


Solution

  • If you are using Underscore and you prefer a functional programming style, which your example suggests, try this:

     _.times(5, function(e) { console.log(e) })