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

181
Views
Objects are not valid as a React child when I mapping an object

I'm starting react and can't solve my problem. I have an object

   modes= {
        "easyMode": {
        "field": 5
        },
        "normalMode": {
        "field": 10
        },
        "hardMode": {
        "field": 15
        }
        }

And I need to map this modes(easyMode, normalMode and hardMode), but I know that I can't map an object, only arrays. Right, but this also doesn't work

const arrayOfObjects = [{ modes }];

return (
    <ul> {arrayOfObjects.map(mode=> <li key={mode}>{mode} </li>)}</ul>)

How I need to do this right?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think it's a duplicate question and you can find a complete answer in this question here

but as a fast answer, for the objects, you have to iterate like this:

Object.keys(modes).map ( mode => {
   console.log(mode,modes[mode]) // you can access the values like this
})
about 4 years ago · Juan Pablo Isaza Report

0

You can use Object.keys() to get an array with modes keys

const modes = {
  easyMode: {
    field: 5,
  },
  normalMode: {
    field: 10,
  },
  hardMode: {
    field: 15,
  },
};

const modesKeys = Object.keys(modes); // ['easyMode','normalMode','hardMode' ]

return (
  <ul> {modesKeys.map(mode => <li key={mode}>{mode}</li>)}</ul>
)
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!