Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

listing range in javascript

//Using spread operator (...) and keys method
[ ...Array(N).keys() ].map( i => i+1);
//Fill/Map
Array(N).fill().map((_, i) => i+1);
//Array.from
Array.from(Array(N), (_, i) => i+1)
//Array.from and { length: N } hack
Array.from({ length: N }, (_, i) => i+1)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #listing #range #javascript
ADD COMMENT
Topic
Name
8+1 =