Skip to content

Instantly share code, notes, and snippets.

mikaello /
Last active Jul 18, 2022 — forked from JamieMason/
Group Array of JavaScript Objects by Key or Property Value

Group array of JavaScript objects by keys

This fork of JamieMason's implementation changes the key parameter to be an array of keys instead of just a single key. This makes it possible to group by multiple properties instead of just one.


const groupBy = keys => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = => obj[key]).join('-');