<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript object key length</title>
</head>
<body>
<pre>
<script type="text/javascript">
var myObj = {}; // indicates an Object is created
myObj.commercial = ".com";
myObj.network= ".net";
myObj.organization= ".org";
myObj.government= ".gov";
document.writeln( Object.keys(myObj) );
// return ["commercial", "network", "organization", "government"]
document.writeln( Object.keys(myObj).length );
// return 4
</script>
</pre>
</body>
</html>