MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiulko7
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
7
Array.from({length: 5}, (v, i) => i); := [0, 1, 2, 3, 4]
Array.from({length: 5}, (v, i) => i);
[0, 1, 2, 3, 4]
13 u/Darren1337 Mar 19 '19 I'm about to end this man's whole career.[...Array(5).keys()] 2 u/NoInkling Mar 19 '19 I can't think of a use case where I'd want to materialize an array of numbers equivalent to their index - I'd just use the map function directly. 1 u/[deleted] Mar 19 '19 Array.from({ length: 5 }, (_, i) => i);for unused variable 2 u/snifty Mar 19 '19 This is neat. I've usually done:new Array(5).fill().map((_,i) => i)I like your way better.
13
I'm about to end this man's whole career.
[...Array(5).keys()]
2
I can't think of a use case where I'd want to materialize an array of numbers equivalent to their index - I'd just use the map function directly.
1
Array.from({ length: 5 }, (_, i) => i);
for unused variable
2 u/snifty Mar 19 '19 This is neat. I've usually done:new Array(5).fill().map((_,i) => i)I like your way better.
This is neat. I've usually done:
new Array(5).fill().map((_,i) => i)
I like your way better.
7
u/action_jackosn Mar 19 '19
Array.from({length: 5}, (v, i) => i);:=[0, 1, 2, 3, 4]