3 ms·
The other comment points out Array.from, which seems pretty nifty. Have not seen it before. I would have used: for(i of Array(1000).keys()) { doSomething() }
by smoe 6y ago
The other comment points out Array.from, which seems pretty nifty. Have not seen it before. I would have used:
for(i of Array(1000).keys()) { doSomething() }
or
[...Array(1000)].forEach(() => doSomething())
- vardaro 6y agowhy create the array? for(let i = 0; i < 1000; i++) button.click() wouldn’t be surprised if Javascript has some weird optimization under the hood!
- epse 6y agoIn this case, there's not much difference. In general, iterating over something rather than using a counter with limits makes it harder to create off by one or other errors due to laziness.