Created
September 16, 2020 03:24
-
-
Save EdwardGoomba/0f4a44336b55c60951eb9504aaa27008 to your computer and use it in GitHub Desktop.
Remove Duplicate Object from Array
This file contains 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
function removeDuplicateObjectFromArray(array, key) { | |
return array.filter((obj, index, self) => | |
index === self.findIndex((el) => ( | |
el[key] === obj[key] | |
)) | |
) | |
} | |
const data = arr.reduce((filter, current) => { | |
const dk = filter.find(item => item.value === current.value); | |
if (!dk) { | |
return filter.concat([current]); | |
} else { | |
return filter; | |
} | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment