UNPKG

@netlify/config

Version:
11 lines (9 loc) 410 B
// Group objects according to a key attribute. // The key must exist in each object and be a string. export const groupBy = function (objects, keyName) { const keys = [...new Set(objects.map((object) => object[keyName]))] return keys.map((key) => groupObjects(objects, keyName, key)) } const groupObjects = function (objects, keyName, key) { return objects.filter((object) => object[keyName] === key) }