Skip to content

Instantly share code, notes, and snippets.

@juanbrusco
Last active June 16, 2022 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanbrusco/524ee38d2c49e433bf7ac80ffe68f264 to your computer and use it in GitHub Desktop.
Save juanbrusco/524ee38d2c49e433bf7ac80ffe68f264 to your computer and use it in GitHub Desktop.
How to Check If an Array Includes an Object in JavaScript
// 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