Last active
December 1, 2022 09:50
-
-
Save aliakakis/3d1295db314029e0d6661b2fd6f13053 to your computer and use it in GitHub Desktop.
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
/** | |
* Remove duplicate values from an array | |
* @param {[] | Object[]} obj - array of values or array of objects | |
* @param {string} [prop] prop - the property in the objects which will be used as a unique value | |
* @returns {[]} | |
*/ | |
export const removeDuplicatesFromArray = (obj, prop) => { | |
return Object.values(obj.reduce((acc, cur) => { | |
return { | |
...acc, | |
[prop ? cur[prop] : cur]: cur | |
} | |
}, {})); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment