Skip to content

Instantly share code, notes, and snippets.

@mohammad-haji
Created May 18, 2018 20:05
Show Gist options
  • Save mohammad-haji/ed84fe16989542813db8e8785051a5f4 to your computer and use it in GitHub Desktop.
Save mohammad-haji/ed84fe16989542813db8e8785051a5f4 to your computer and use it in GitHub Desktop.
/**
* remove duplicates from array object with specific key
* @param arr
* @param key
* @return {Array.<T>|*}
*/
export function removeDuplicates(arr, key) {
return arr.filter((obj, index, arr) => {
return arr.map(mapObj => {
return mapObj[key]
}).indexOf(obj[key]) === index;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment