Last active
June 16, 2022 18:38
-
-
Save juanbrusco/524ee38d2c49e433bf7ac80ffe68f264 to your computer and use it in GitHub Desktop.
How to Check If an Array Includes an Object in JavaScript
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
// An array of objects | |
var persons = [{name: "Harry"}, {name: "Alice"}, {name: "Peter"}]; | |
// Find if the array contains an object by comparing the property value | |
if(persons.some(person => person.name === "Peter")){ | |
alert("Object found inside the array."); | |
} else{ | |
alert("Object not found."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment