title: How to efficiently check if variable is Array or Object (in NodeJS & V8)?
body: <p>Is there any way to efficiently check if the variable is Object or Array, in NodeJS &amp; V8? </p>
  
  <p>I'm writing a Model for MongoDB and NodeJS, and to traverse the object tree I need to know if the object is simple (Number, String, ...) or composite (Hash, Array).</p>
  
  <p>It seems that V8 has fast built-in <code>Array.isArray</code>, but how to check if object is an Object? I mean complex object like hash <code>{}</code> or instance of class, not something like <code>new String()</code>?</p>
  
  <p>Usually it may be done as this:</p>
  
  <pre><code>Object.prototype.toString.call(object) == "[object Object]"
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>object === Object(object)
  </code></pre>
  
  <p>But it seems that this operations aren't cheap, maybe there's some more efficient? It's ok if it's not universal and doesn't works on all engines, I need it only to work on V8.</p>