javascript - do <something> N times (declarative syntax) -
is there way in javascript write easily:
[1,2,3].times { something(); } any library might support similar syntax maybe?
update: clarify - something() called 1,2 , 3 times respectively each array element iteration
this answer based on array.foreach, without library, native vanilla.
to call something() 3 times, use:
[1,2,3].foreach(function(i) { something(); }); to complete questions, here's way call something() 1, 2 , 3 times respectively:
it's 2017, may use es6:
[1,2,3].foreach(i => array(i).fill(i).foreach(_ => { something() })) or in old es5:
[1,2,3].foreach(function(i) { array(i).fill(i).foreach(function() { something() }) }))
Comments
Post a Comment