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

198
Views
Populating data on a table in React

I have some nested data and i want to populate it in a table in react. As shown in the image, every method are in one row. How can i make a row for every method with its corresponding pages name? enter image description here

const methods = [{
  id: "1",
  name: 'First',
  pagesName: [{
    name: 'Login',
    message: 'Login Notification Message',
    messageType: 'Warning'
  },
  {
    name: 'Edit',
    message:'Edit Notification Message',
    messageType: 'Info'
  }]
},
{
 id: "2",
  name: 'Second',
  pagesName: [{
    name: 'Admin',
    message: 'Admin Notification Message',
    messageType: 'Info'
  },
  {
   name: 'Edit',
   message: 'Edit Notification Message',
   messageType: 'Warning'
}
]}
]

Table

<tbody>
   {methods.map((p, key) => {
       return (
           <tr>
           <td>{key}</td>
           <td>{p.name}</td>
           {p.pagesName.map((n, key) => {
           return (
              <>
              <td>{n.name}</td>
              <td>{n.message}</td>
              <td>{n.messageType}</td>
              </>
            )
            })}
           </tr>
           )})
           }
   </tbody>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use Array.map() like this: https://jsfiddle.net/Lc3m08dn/58/

<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>PagesName</th>
            <th>Message</th>
            <th>messageType</th>
        </tr>
    </thead>
    {methods.map(method => (
        <tbody>
            <tr>
                <td rowspan={method.pagesName.length + 1}>{method.id}</td>
                <td rowspan={method.pagesName.length + 1}>{method.name}</td>
            </tr>
            {method.pagesName.map(page => (
                <tr>
                    <td>{page.name}</td>
                    <td>{page.message}</td>
                    <td>{page.messageType}</td>
                </tr>
            ))}
        </tbody>
    ))}
</table>
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!