Skip to content

Instantly share code, notes, and snippets.

@andrit
Created September 24, 2018 15:26
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 andrit/25eaad5afe397e9bc307e3940a295aee to your computer and use it in GitHub Desktop.
Save andrit/25eaad5afe397e9bc307e3940a295aee to your computer and use it in GitHub Desktop.
let array = [ 
  {hash: "11223344", value: "abc"},
  {hash: "11223344", value: "def"},
  {hash: "22113344", value: "jkl"},
  {hash: "22113344", value: "zyw"},
  {hash: "33221144", value: "omn"},
  {hash: "33221144", value: "xyz"}
];

let a = [...new Set(array.map(i => i.hash))]
  .map(hash => {
    return { hash, values: array.filter(v => v.hash == hash).map(v => v.value) }
  })

console.log(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment