How to efficiently count the number of keys/properties of an object in JavaScript?