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

185
Views
Trying to rendering the options based on json data but getting map is not a function

I am trying to get a model based on the Brand. But getting the error when selection the next option

Error says bikeBrand is not a Function

Below is the Json data getting from backend

response from backend { BMW:["F900R", "F900XR"], KTM:["125 Duke", "250 Duke"]}

Then storing on the state using useState hook in React

const [bikeBrands, setBikeBrands] = useState("")

First option value is storing in below hook too

const [selectedBrand, setSelectedBrand] = useState("")

Problem is in the second selection option.

<select onChange={(e) => setSelectedBrand(e.target.value)}>
                        <option>Choose brand</option>
                        {Object.keys(bikeBrands).map((bikeBrand, index) => {
                            return <option>{bikeBrand}</option>
                        })}
                    </select>
                    <select onChange={(e) => setModel(e.target.value)}>
                        <option>Choose Model</option>
                        {Object.keys(bikeBrands).map((bikeBrand, index) => {
                            bikeBrand.map((brandModels, index) => {
                                return <option>{brandModels}</option>
                            })
                        })}

                    </select>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As you are doing

{Object.keys(bikeBrands).map((bikeBrand, index) => {
  bikeBrand.map((brandModels, index) => {
   return <option>{brandModels}</option>
  })
})}

note that Object.keys(bikeBrands) gives you array of keys, and these individual keys (one at a time) are stored in bikeBrand.

This bikeBrand is a variable which holds string BMW or KTM not the value.
So instead of writing bikeBrand.map
Use bikeBrands[bikeBrand].map to access Array values.

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!