react-epoch-picker
Version:
A React UI component for choosing an date epoch, starting zoomed out at millenniums and going down through the centuries, decades and years.
14 lines (13 loc) • 388 B
JavaScript
/**
* accepts a data array and key and finds the nested object that has a matching key field
*
* @param {array} data
* @param {string} key
*/
export default function findEpochArrayIndex(data, key) {
const index = data.findIndex(({ key: k }) => key === k);
if (index === -1) {
throw new Error(`Could not locate the key ${key}`);
}
return index;
}