Skip to content

Instantly share code, notes, and snippets.

@IOIO72
Last active October 14, 2019 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IOIO72/aaae4f48b86cb0fd62d87d81d36cda82 to your computer and use it in GitHub Desktop.
Save IOIO72/aaae4f48b86cb0fd62d87d81d36cda82 to your computer and use it in GitHub Desktop.
An array of objects of same structure is given. Each object contains a property `label` besides other properties. Same labels are equal accross the objects. The goal is to group the objects by the labels.
// Get an array of all labels with unique entries.
const uniqueLabels = [...new Set(apps.map(item => item.label))];
// Transform the original array of objects to an array of label groups.
const groupedApps = uniqueLabels.map(label => ({ label, stores: apps.filter(app => app.label.includes(label)) }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment