TinyBase logoTinyBase β

forEachTableCell

The forEachTableCell method takes a function that it will then call for each Cell used across the whole Table.

forEachTableCell(
  tableId: string,
  tableCellCallback: TableCellCallback,
): void
TypeDescription
tableIdstring

The Id of the Table containing the Cells to iterate over.

tableCellCallbackTableCellCallback

The function that should be called for every Cell Id used across the whole Table.

returnsvoid

This has no return value.

This method is useful for iterating over the Cell structure of the Table in a functional style. The tableCellCallback parameter is a TableCellCallback function that will be called with the Id of each Cell and the count of Rows in the Table in which it appears.

Example

This example iterates over each Cell Id used across the whole Table.

import {createStore} from 'tinybase';

const store = createStore().setTables({
  pets: {fido: {species: 'dog'}, felix: {species: 'cat', legs: 4}},
});
store.forEachTableCell('pets', (cellId, count) => {
  console.log(`${cellId}: ${count}`);
});
// -> 'species: 2'
// -> 'legs: 1'

Since

v3.3.0