Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Check If an Object Has a Specific Property in JavaScript</title> <script> // Sample object var myCar = { make: "Ford", model: "Mustang", year: 2021 }; // Setting a property to undefined myCar.model = undefined; // Deleting a property delete myCar.year; // Test if properties exist document.write(("make" in myCar) + "<br>"); // Prints: true document.write(("model" in myCar) + "<br>"); // Prints: true document.write("year" in myCar); // Prints: false </script> </head> <body> <!-- Result will be printed here --> </body> </html>