Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!