Created
December 6, 2021 13:59
-
-
Save cn-2k/e01b79babea243ef5e87ef5a843dbd46 to your computer and use it in GitHub Desktop.
Comparing two arrays of object
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
// 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