how to make an array of a value from 1 to the number 1

how to make an array of a value from 1 to the number

[ ...Array(N).keys() ].map( i => i+1);

Here is what the above code is Doing:
1. We’re creating an array of N elements.
2. We’re mapping each element to its index + 1.
3. We’re using the spread operator to convert the array-like object into an array.

Similar Posts