UNPKG

es-toolkit

Version:

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

19 lines (15 loc) 444 B
'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 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; } exports.groupBy = groupBy;