UNPKG

country-codes-list

Version:

List of codes per country (languages, calling codes, currency codes, etc) with full TypeScript support.

20 lines (19 loc) 658 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Groups an array by a specified key. * @param array - The array to group. * @param key - The key to group the array by. * @returns An object where each key is a unique value from the array, and each value is an array of items from the original array that match the key. */ function groupBy(array, key) { return array.reduce((result, item) => { const groupKey = String(item[key]); if (!result[groupKey]) { result[groupKey] = []; } result[groupKey].push(item); return result; }, {}); } exports.default = groupBy;