There are several ways to do this. The easiest way to use Object.keys( documentation ):
console.log(Object.keys(keyValues).length);
This is essentially equivalent to:
var count = 0;
for(var key in keyValues){
if(keyValues.hasOwnProperty(key)) count++;
}
console.log(count):
Please note that only keys belonging to the object itself will be counted, not keys in the prototype chain of the object. If you need to count all the keys (including the keys in the prototype chain), just omit the call hasOwnPropertyabove:
var count = 0;
for(var key in keyValues){
count++;
}
console.log('all keys, including prototype chain: ' + count):
, , , , , , . ( , ), Object.getOwnPropertyNames() () . , , , , : - , , , , . , !