Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Determine If Object is in Array in JavaScript</title> </head> <body> <script> // 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")){ document.write("Object found inside the array."); } else{ document.write("Object not found."); } </script> </body> </html>