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

Posted by mjs on Stack Overflow See other posts from Stack Overflow or by mjs
Published on 2008-09-24T08:56:21Z Indexed on 2010/05/17 5:50 UTC
Read the original article Hit count: 250

Filed under:
|
|
|
|

What's the fastest way to count the number of keys/properties of an object? It it possible to do this without iterating over the object? i.e. without doing

var count = 0;
for (k in myobj) if (myobj.hasOwnProperty(k)) count++;

Firefox provides a magic __count__ property, but this isn't available in other implementations.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about properties