One Liner

Create array from 1 to n

const generateArray = (n) => Array.from({length: n}, (_, i) => i + 1)

Example

generateArray(10); //  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Last Update: 15:54 - 09 April 2024

On this page