Uitvoer van 'n versameling objekte as 'n HTML-tabel in React

Kom ons sê ons het weer ons versameling met produkte:

jsxconst prods = [
  {id: 1, name: 'product1', cost: 100},
  {id: 2, name: 'product2', cost: 200},
  {id: 3, name: 'product3', cost: 300},
];

Kom ons voer die elemente van ons versameling uit as 'n HTML-tabel:

jsxfunction App() {
  const rows = prods.map(function(item) {
    return <tr key={item.id}>
      <td>{item.name}</td>
      <td>{item.cost}</td>
    </tr>;
  });
  
  return <table>
    <tbody>
      {rows}
    </tbody>
  </table>;
}

Kom ons voer kolomopskrifte vir ons tabel by:

jsxfunction App() {
  const rows = prods.map(function(item) {
    return <tr key={item.id}>
      <td>{item.name}</td>
      <td>{item.cost}</td>
    </tr>;
  });
  
  return <table>
    <thead>
      <tr>
        <td>naam</td>
        <td>koste</td>
      </tr>
    </thead>
    <tbody>
      {rows}
    </tbody>
  </table>;
}
Задание 1

In die komponent App word die volgende versameling gegee:

jsxconst users = [
  {id: 1, name: 'user1', surn: 'surn1', age: 30},
  {id: 2, name: 'user2', surn: 'surn2', age: 31},
  {id: 3, name: 'user3', surn: 'surn3', age: 32},
];

Voer die elemente van hierdie versameling uit as 'n tabel table sodat elke veld van die objek in sy eie td-etik beland. Maak opskrifte vir die kolomme van jou tabel.