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

178
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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