TinyBase logoTinyBase β

forEachRow

The forEachRow method takes a function that it will then call for each Row in a specified Table.

forEachRow(
  tableId: string,
  rowCallback: RowCallback,
): void
TypeDescription
tableIdstring

The Id of the Table to iterate over.

rowCallbackRowCallback

The function that should be called for every Row.

returnsvoid

This has no return value.

This method is useful for iterating over the Row structure of the Table in a functional style. The rowCallback parameter is a RowCallback function that will be called with the Id of each Row, and with a function that can then be used to iterate over each Cell of the Row, should you wish.

Example

This example iterates over each Row in a Table, and lists each Cell Id within them.

import {createStore} from 'tinybase';

const store = createStore().setTables({
  pets: {
    fido: {species: 'dog'},
    felix: {color: 'black'},
  },
});
store.forEachRow('pets', (rowId, forEachCell) => {
  console.log(rowId);
  forEachCell((cellId) => console.log(`- ${cellId}`));
});
// -> 'fido'
// -> '- species'
// -> 'felix'
// -> '- color'

Since

v1.0.0