Great article!
It's worth noting that the first 2 examples can be written ever so slightly shorter using Array.from as the Array.from method supports a mapping function as it's second argument.
Array.from
Here's the first example using Array.from:
Array.from({ length: 1000 }, Math.random)
And the second example:
Array.from({ length: 1000 }, (v, i) => i)
You're right! This way is slightly shorter! I'll replace mine with them Thank you mate!
Here is what I use
[...Array(1000).keys()]
Array from for the win I had an issue with array fill hahaha
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article!
It's worth noting that the first 2 examples can be written ever so slightly shorter using
Array.from
as theArray.from
method supports a mapping function as it's second argument.Here's the first example using
Array.from
:And the second example:
You're right! This way is slightly shorter! I'll replace mine with them
Thank you mate!
Here is what I use
Array from for the win I had an issue with array fill hahaha
How Array.fill can break arrays!
Médéric Burlet ・ Oct 7 '20 ・ 2 min read