Skip to content

Instantly share code, notes, and snippets.

@johnnyferreiradev
Created August 7, 2020 14:27
Show Gist options
  • Save johnnyferreiradev/1ed1d2159ef63074812c6e7fb9cf8c60 to your computer and use it in GitHub Desktop.
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.
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