skip to content
developertype

snippets

filter:96 snippets
js-gen-groupby·javascript·general
function groupBy(items, key) {
  return items.reduce((acc, item) => {
    const k = typeof key === "function" ? key(item) : item[key];
    (acc[k] ||= []).push(item);
    return acc;
  }, {});
}