Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Iterate Over Properties of an Object in JavaScript</title> <script> // Sample object var obj = { make: "Ford", model: "Mustang", color: "red", year: 2021 }; // Iterate through object properties for(var key in obj) { document.write("<p>" + key + " -> " + obj[key] + "</p>"); } </script> </head> <body> <!-- Result will be printed here --> </body> </html>