title: Determine how many fields a Javascript object has
body: <p>I have a Javascript object that I'm trying to use as a "hashmap". The keys are always strings, so I don't think I need anything as sophisticated as what's described in <a href="https://stackoverflow.com/questions/368280/javascript-hashmap-equivalent">this SO question</a>. (I also don't expect the number of keys to go above about 10 so I'm not particularly concerned with lookups being O(n) vs. O(log n) etc.) </p>
  
  <p>The only functionality I want that built-in Javascript objects don't seem to have, is a quick way to figure out the number of key/value pairs in the object, like what Java's <a href="http://java.sun.com/javase/6/docs/api/java/util/Map.html#size()" rel="nofollow noreferrer">Map.size</a> returns. Of course, you could just do something like:</p>
  
  <pre><code>function getObjectSize(myObject) {
    var count=0
    for (var key in myObject)
      count++
    return count
  }
  </code></pre>
  
  <p>but that seems kind of hacky and roundabout. Is there a "right way" to get the number of fields in the object?</p>