Skip to content

Instantly share code, notes, and snippets.

@progging
Created May 22, 2019 08:10
Show Gist options
  • Save progging/1159726f2704ca06641ab2a41f408584 to your computer and use it in GitHub Desktop.
Save progging/1159726f2704ca06641ab2a41f408584 to your computer and use it in GitHub Desktop.
Group by multiple properties using lodash
const items = [
{ key1: "el200", key2: "id001", value: "bulb tumeric hell of hot chicken" },
{ key1: "el200", key2: "id001", value: "iceland shaman fashion axe squid vice" },
{ key1: "el200", key2: "id001", value: "pin venmo letterpress cloud bread" },
{ key1: "el400", key2: "id002", value: "YOLO flexitarian, swag sriracha" },
{ key1: "el500", key2: "id002", value: "health goth chillwave" }
];
const grouped = _.groupBy(items, item => `"${item.key1}+${item.key2}"`);
console.log(grouped);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment