Created
March 18, 2017 00:13
-
-
Save jeffward01/7c0e3935bcabf826765ed73d032ca0e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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