UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

15 lines (13 loc) 348 B
function groupBy(arr, getKeyFromItem) { const result = {}; for (let i = 0; i < arr.length; i++) { const item = arr[i]; const key = getKeyFromItem(item, i, arr); if (!Object.hasOwn(result, key)) { result[key] = []; } result[key].push(item); } return result; } export { groupBy };