TinyBase logoTinyBase β

forEachValue

The forEachValue method takes a function that it will then call for each Value in a Store.

forEachValue(valueCallback: ValueCallback): void
TypeDescription
valueCallbackValueCallback

The function that should be called for every Value.

returnsvoid

This has no return value.

This method is useful for iterating over the Value structure of the Store in a functional style. The valueCallback parameter is a ValueCallback function that will be called with the Id and value of each Value.

Example

This example iterates over each Value in a Store, and lists its value.

import {createStore} from 'tinybase';

const store = createStore().setValues({open: true, employees: 3});
store.forEachValue((valueId, value) => {
  console.log(`${valueId}: ${value}`);
});
// -> 'open: true'
// -> 'employees: 3'

Since

v3.0.0