2 ms·
I really don't love it, but Array(5).fill().forEach(() => console.log('hello'))
by klardotsh 8y ago
I really don't love it, but
Array(5).fill().forEach(() => console.log('hello'))
- ljm 8y agoI've also taken to: Array.from({ length: 5 }).forEach(...) But I'm not sure what you gain from that compared to just wrapping a for loop in a function. You still don't get ranges the way you do in, say Ruby: ('a'..'z').each {|letter| puts letter }
- klardotsh 8y agoYeah, I mostly work in Python, where ranging and slicing is amazing. JS has a lot to catch up on in that regard.