Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
How to define array range of array of numbers in TypeScript

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?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda