Skip to content

Instantly share code, notes, and snippets.

@jeffward01
Created March 18, 2017 00:13
Show Gist options
  • Save jeffward01/7c0e3935bcabf826765ed73d032ca0e8 to your computer and use it in GitHub Desktop.
Save jeffward01/7c0e3935bcabf826765ed73d032ca0e8 to your computer and use it in GitHub Desktop.
tmp = [
{
uniqueCode = 1234,
selected = true,
otherVal = 'abc'
},
{
uniqueCode = 5678,
selected = false,
otherVal = 'abc'
},
{
uniqueCode = 1234,
selected = true,
otherVal = 'def'
}
];
function removeDuplicates(arr, prop) {
var new_arr = [];
var lookup = {};
for (var i in arr) {
lookup[arr[i][prop]] = arr[i];
}
for (i in lookup) {
new_arr.push(lookup[i]);
}
return new_arr;
}
var uniqueArray = removeDuplicates(tmp, "uniqueCode");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment