In Next.js I create a function component and use useState hook to declare variable for store array of digits like this
const [digits, setDigits] = useState<number[]>();
But I also want to define the range of array generic, something like Array(3) (but not [number, number, number] because that is too long)
How to solve this?
You can do something like this:
const data = new Array<number>(100)
An array length of 100 where the elements have a type of number. Array comes with with a fill function to initialize your array if needed, for example
const array = new Array<number>(100).fill(9)
An array of length 100 where all indexes will be number 9.