Possible Duplicate:
Length of Javascript Associative Array
hash_table = {a: 131, b: 222, c:313} The length method is not working of course since it will be confused with a key.
So how do I do it?
Possible Duplicate:
Length of Javascript Associative Array
hash_table = {a: 131, b: 222, c:313} The length method is not working of course since it will be confused with a key.
So how do I do it?
Object.keys will return all the keys in the object as a list, then use length to get the length.
example:
Object.keys(hash_table).length NOTE that this is ECMA 5 and may not be available in some browsers. see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys for full document.
var count = 0; for ( property in hash_table ) count++; length property is only updated for numerical properties,i.e. arr[0] = 42.. Non-numerical properties do not update length and should not be used for arrays as it is just confusing.