Consider this situation where you would require an array of certain number or till certain number say from 0 or any other start point, to resolve this we use number-to-array functionality.
yarn add number-to-array
const { numberToArray} = require('number-to-array')
-
To get the number of array from 0 to the provided input :
numberToArray(5);
Output :
[ 0, 1, 2, 3, 4, 5 ]
-
To get the number of array from provided start point to provided end point :
numberToArray(5, 7);
Output:
[ 5, 6, 7 ]
-
To get array out of string provided with a seperator:
numberToArray('hey hey hey',true, 'e') // true indicates its a string
Output:
[ 'h', 'y h', 'y h', 'y' ]
The code is all yours :)