Prikaz polja objektov kot HTML tabele v Reactu

Naj imamo spet dano naše polje s produkti:

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

Prikažimo elemente našega polja v obliki HTML tabele:

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>;
}

Dodajmo naslove stolpcev naši tabeli:

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>ime</td>
        <td>cena</td>
      </tr>
    </thead>
    <tbody>
      {rows}
    </tbody>
  </table>;
}
Задание 1

V komponenti App je dano naslednje polje:

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},
];

Prikažite elemente tega polja v obliki tabele table tako, da vsako polje objekta gre v svojo oznako td. Naredite naslove stolpcev vaše tabele.