Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Count the Number Enumerable Properties of a JavaScript Object</title> <script> // Creating an object var myObj = new Object(); // Adding properties myObj["name"] = "Peter"; myObj["age"] = 24; myObj["gender"] = "Male"; // Printing object in console console.log(myObj); // Prints: {name: "Peter", age: 24, gender: "Male"} // Getting object length var size = Object.keys(myObj).length; document.write(size); // Prints: 3 </script> </head> <body> <!-- Result will be printed here --> </body> </html>