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

146
Vistas
Reactjs select value opition value map iteration with default value

I am using react application in iteration I have a map method with some doubt, I have a select box with fill number based on iteration 0 to coming value base,my expected output is [{label:0,value:0},{label:1,value:1},{label:2,value:2}] but coming output is =[{label:1,value:1},{label:2,value:2}], I know how to do in for loop but, i want know map method beacuse i am react application,i tried fill , and join method it's not working please help uss

let value = 2
[...Array(parseInt(value)).keys()].map((x, index) => (
    {
      label: x + 1,
      value: x + 1,
   }
 ))

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

0

Array(2); will create an empty array with length is 2, so when you want your array is [0, 1, 2], the length should be Array(3);. So I update your code into Array(value + 1) and remove parseInt.

let value = 2
const result = [...Array(value + 1).keys()].map((x) => ({
  label: x,
  value: x,
}))

console.log(result);

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