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

89
Views
Printing JSON as a list in React

I'm trying to print JSON data (this) in React. I came to this:

const print = data.forEach(e => {
    e.data.map(el => {
      return(
        <li>{el.account_id}</li>
      )
    })
  });
  return (
    <div>
      <ul>
        {print}
      </ul>
    </div>
  );

Yet it doesn't work (when i do console.log(el.account_id) it logs everything, but doesn't display the data in the ul). What am i doing wrong?

EDIT:

const print = data.map(e => {
        return e.data.map(el => {
          return(
            <li>{el.account_id}</li>
          )
        })
      });
return (
   <div>
      <ul>
        {print}
      </ul>
   </div>
);

is the correct way to do it.

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

0

You're very close. forEach does not return anything. Use map.

You probably want something closer to this:

const print = data.map(record => (
  <div key={record.meta.page}>
    <h3>PAGE: {record.meta.page}</h3>
    <ul>
      {record.data.map(item => {
        return (<li key={item.account_id}>{item.account_id}</li>)
      })
      }
    </ul>
  </div>
))

return (
  <div>
    {print}
  </div>
)
about 4 years ago · Juan Pablo Isaza Report

0

const print = data.map(el => {
  return(
    <li>{el.account_id}</li>
  )
})
return (
  <div>
    <ul>
      {print}
    </ul>
  </div>
);

you dont need the forEach

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!