1
1
12332112019-09-11 17:40:50
JavaScript
1233211, 2019-09-11 17:40:50

How to display data in a table?

There is an array with objects like this:
[{arr: [1,2,3,4,5]},{arr: [10, 20, 30, 40, 50]}]
How to display data in a table so that it looks like this on the page? (indentation is not important)
5d7907429b98a818023689.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-09-11
@1233211

Make rows from columns:

const rows = data.length
  ? data[0].arr.map((n, i) => data.map(m => m.arr[i]))
  : [];

Well, render:
<table>
  <tbody>
    {rows.map(n => <tr>{n.map(m => <td>{m}</td>)}</tr>)}
  </tbody>
</table>

https://jsfiddle.net/s9q0xr78/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question