Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Check If an Object Has a Key in JavaScript</title> <script> // Sample object var myCar = { make: "Ford", model: "Mustang", year: 2021 }; // Test if a key exists in the object if("model" in myCar === true) { document.write("The specified key exists in the object."); } else { document.write("The specified key doesn't exist in the object."); } </script> </head> <body> <!-- Result will be printed here --> </body> </html>