I have a number for example 10. I want to explode it sequentially in order from 1 until 10, e.g 1,2,3,4,5,6,7,8,9,0
javascript
var number = 10
var array = [1,2,3,4,5,6,7,8,9,10] // How to convert the number into this?
I have a number for example 10. I want to explode it sequentially in order from 1 until 10, e.g 1,2,3,4,5,6,7,8,9,0
javascript
var number = 10
var array = [1,2,3,4,5,6,7,8,9,10] // How to convert the number into this?
console.log(Array.apply(null, {length:11}).map(Number.call, Number).slice(1));
Output
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
Original idea from Creating range in JavaScript - strange syntax and it has an awesome explanation of how this answer really works. Its a must read.
Lets do a quite pseudo code here and you can try it like this:
Create Array [size], consider the size to be the number entered like 10 for example;
Create a loop FOR or WHILE
Until number (10) reaches 0... I'm sure you can do this by your self.