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

177
Visualizações
Create options list for react Select from single dimension array

I have an array like [ 123, 456 ] and it needs to be mapped into a react Select with label and value pairs so the "options" will be: 0: {label: "123", value: 123} 1: {label: "456", value: 456}

I just can't seem to get the map syntax to work for the source array (i.e. 0: 123, 1: 456)

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can write like this:

array.map((item)=> <Option label={item} value={item}/>)

This return an array of holding options with your label and value

about 4 years ago · Santiago Trujillo Relatório

0

If you need the options array you can write this:

let Myarray= [ 123, 456 ];
Myarray.map((item)=> <Option label={item} value={item}/>)

or If you need an array with label and value:

let Myarray= [ 123, 456 ];
let FinalArray=[];
Myarray.map((item)=>[...FinalArray,{label:item,value:item}])

if you want to put " to value

let Myarray= [ 123, 456 ];
let FinalArray=[];
Myarray.map((item)=>[...FinalArray,{label:item.toString(),value:item}])
about 4 years ago · Santiago Trujillo 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