Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Find the Length of an Object in JavaScript</title> <script> // Sample object var myObj = { make: "Ferrari", model: "Portofino", fuel: "Petrol", year: 2018 }; // Getting object length var size = Object.keys(myObj).length; document.write(size); // Prints: 4 </script> </head> <body> <!-- Result will be printed here --> </body> </html>