Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create an array from 1 to n javascript

Array.from(Array(10).keys())
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

[...Array(10).keys()]
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Array.from({length: 10}, (_, i) => i + 1)
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Comment

javascript create array from 1 to n

// Javascript create array from 1 to n 

[...Array(n+1).keys()].slice(1)

// E.g. for n = 10:
// [...Array(11).keys()].slice(1)
// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Comment

PREVIOUS NEXT
Code Example
Javascript :: to int jquery 
Javascript :: get page url without params in javascript 
Javascript :: jquery get second td of tr 
Javascript :: setinterval jquery 
Javascript :: jQuery ui embed 
Javascript :: check react version terminal windows 
Javascript :: react native rename 
Javascript :: remove attribute jquery 
Javascript :: electron remove default menu 
Javascript :: Basic JavaScript: Use Recursion to Create a Range of Numbers 
Javascript :: npm run dev mix not found 
Javascript :: react native textInput numbers only 
Javascript :: javascript scroll to top of page 
Javascript :: go to anchor jquery 
Javascript :: how to makewebapge editable 
Javascript :: regex remove html tags 
Javascript :: javascript convert string to 2 decimal 
Javascript :: javascript element by class 
Javascript :: reload page jquery timer 
Javascript :: electronjs start with devtools enabled 
Javascript :: js console log with color 
Javascript :: sequelize order by date 
Javascript :: es module __dirname alternative 
Javascript :: one year ago javascript date 
Javascript :: slugify text javascript 
Javascript :: store data in localstorage javascript 
Javascript :: check for internet explorer browser in javascript 
Javascript :: javascript start function on load 
Javascript :: javascript how to check for an empty object 
Javascript :: check if date time string is invalid date js 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =