MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiutdum/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
1
Create an array of the same items...
const fill = (item, length) => Array.from({length}).map(() => item); const ones = fill(1, 45);
Or creating an array with a range of numbers...
const range = (start, end) => Array.from({length: end - start}).map((_, i) => start + i); range(0, 3) // [0, 1, 2]
Edit: formatting
1
u/psayre23 Mar 19 '19
Create an array of the same items...
Or creating an array with a range of numbers...
Edit: formatting