Created
August 7, 2020 14:27
-
-
Save johnnyferreiradev/1ed1d2159ef63074812c6e7fb9cf8c60 to your computer and use it in GitHub Desktop.
Function to merge two arrays of objects based on a property, preventing repetition.
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
const mergeArrayOfObjects = (arrayA, arrayB, prop) => { | |
const reduced = arrayA.filter((aItem) => !arrayB.find(bItem => aItem[prop] === bItem[prop])); | |
return reduced.concat(arrayB); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment