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

80
Views
React map object as array?

I know its possible to map an array of some sort like so:

{sumArray.map((summary, index) => (
    <Col className="stat-element" key={index}>
        
    </Col>
))}

However I want to map a single object by each of its properties:

const [summary, setSummary] = useState([{rank: 0}, {trending: 0}, {totalTaskCompleted: 0}, {avgTaskCorrect: 0}, {avgTaskTime: 0 }]);

    useEffect(() => {
        if (parentToChild){
            console.log(parentToChild)
            const result = Object.values(parentToChild);
            setSummary(result);
            console.log(result);
        }

      }, [])

However on output this strips the properties title, how do I make it retain the properties name so I can display each within the following? :

{summary.map((property, index) => (
    <Col className="stat-element" key={index}>
        {index} {propertyname} {property}
    </Col>
))}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you should then declare summary as an object and not an array and then you could use the Object.keys methods:

const [summary, setSummary] = useState({rank: 0, trending: 0, totalTaskCompleted: 0, avgTaskCorrect: 0, avgTaskTime: 0 });

(...)

Object.keys(summary).map((key, index) => (
    <Col className="stat-element" key={index}>
        {index} {key} {summary[key]}
    </Col>
))}
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!