Table data
abstract
A table works with an array of items, where each item is a row, and each property or member is a cell.
An item may come as an object or as an array.
pattern: the item is an object
const items = [
{ position: 6, mass: 12.011, symbol: "C", name: "Carbon" },
{ position: 7, mass: 14.007, symbol: "N", name: "Nitrogen" },
{ position: 39, mass: 88.906, symbol: "Y", name: "Yttrium" },
{ position: 56, mass: 137.33, symbol: "Ba", name: "Barium" },
{ position: 58, mass: 140.12, symbol: "Ce", name: "Cerium" },
]
pattern: the item is an array
const items = [
[6, 12.011, "C", "Carbon"],
[7, 14.007, "N", "Nitrogen"],
[39, 88.906, "Y", "Yttrium"],
[56, 137.33, "Ba", "Barium"],
[58, 140.12, "Ce", "Cerium"],
]
We may come with this data by transforming an array of objects to an array of arrays:
const items = players.map((p) => [p.name, p.level, p.class])
headers
An array usually comes with headers. We may provide them in an array.
const headers = ["Element position", "Atomic mass", "Symbol", "Element name"]