Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda