Skip to content

Instantly share code, notes, and snippets.

@olaysco
Last active June 24, 2019 11:14
Show Gist options
  • Save olaysco/160b942dcb0e4d2c958bbde4e24db1a4 to your computer and use it in GitHub Desktop.
Save olaysco/160b942dcb0e4d2c958bbde4e24db1a4 to your computer and use it in GitHub Desktop.
Javascript function to substract Arrays of Object A from Arrays of Object B (A-B) i.e. getting the differences between two Arrays of Object
/**
* this function assumes array A and array B have an id key in
* each of their object
**/
function subtractArray(arrayA, arrayB){
return arrayA.filter((aElem)=>{
return !arrayB.find(bElem=>bElem.id === aElem.id)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment