I want to declare an array having integer elements 1 to n, where n can be 100 or greater. So, its obvious that I don’t want to add all integers (1 to 100) manually.
Can someone suggest me the simplest way to do this in javascript?
I think there should be something like this: [1..n], but its not working.
EDIT:
MORE CLARIFICATION OF REQUIREMENT:
I need this: var arr = [1,2,3,4,5,6,7,8,9,10,11,....,100] but I don’t want to declare like this where I have to write every element manually. I need something better option to do this.
You could do this like:
Just create an array and fill them with a for loop. You don’t have to declare the
varat the beginning.Check This Example.
See the result in the console