Skip to content

Instantly share code, notes, and snippets.

@cn-2k
Created December 6, 2021 13:59
Show Gist options
  • Save cn-2k/e01b79babea243ef5e87ef5a843dbd46 to your computer and use it in GitHub Desktop.
Save cn-2k/e01b79babea243ef5e87ef5a843dbd46 to your computer and use it in GitHub Desktop.
Comparing two arrays of object
// comparing by id
const output = yourFirstArray.filter((item1) => !yourSecondArray.some((item2) => item1.id == item2.id))
console.log(output)
// or
// attention: "id" is a variable of yourFirstArray filter method
const output = yourFirstArray.filter(({ id }) => !yourSecondArray.find(item => item.id == id));
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment