Skip to content

Instantly share code, notes, and snippets.

@andrit
Last active September 24, 2018 15:42
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/9ca35612fbeb612d32daa1585ff403f9 to your computer and use it in GitHub Desktop.
Save andrit/9ca35612fbeb612d32daa1585ff403f9 to your computer and use it in GitHub Desktop.
let arr = [ 
                 {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 temparray = [];
    let newarray = [];

arr.map((x) => {
      var index = temparray.indexOf(x.hash);
      if (index === -1){
      temparray.push(x.hash);
      newarray.push({ hash: x.hash, value: [x.value] });
      } else {
      newarray[index].value.push(x.value);
    }
     
    });
    ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment