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

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

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