TinyBase logoTinyBase

hasMetric

The hasMetric method returns a boolean indicating whether a given Metric exists in the Metrics object, and has a value.

hasMetric(metricId: Id): boolean
TypeDescription
metricIdId

The Id of a possible Metric in the Metrics object.

returnsboolean

Whether a Metric with that Id exists.

Example

This example shows two simple Metric existence checks.

const store = createStore();
const metrics = createMetrics(store);
metrics.setMetricDefinition('highestPrice', 'species', 'max', 'price');

console.log(metrics.hasMetric('lowestPrice'));
// -> false
console.log(metrics.hasMetric('highestPrice'));
// -> false
store.setTable('species', {dog: {price: 5}, cat: {price: 4}});
console.log(metrics.hasMetric('highestPrice'));
// -> true