title: Testing if the element is an array, in Javascript
body: <p>To check if an element is an array in JavaScript, I have always used Crockford's function (<em>pg 61 of The Good Parts</em>):</p>
  
  <pre><code>var is_array = function (value) {
      return value &amp;&amp;
          typeof value === 'object' &amp;&amp;
          typeof value.length === 'number' &amp;&amp;
          typeof value.splice === 'function' &amp;&amp;
          !(value.propertyIsEnumerable('length'));
  }
  </code></pre>
  
  <p>But if I'm not mistaken, recently some guy from Google had found a new way on how to test for a JavaScript array, but I just can't remember from where I read it and how the function went.</p>
  
  <p>Can anyone point me to his solution please?</p>
  
  <hr>
  
  <p><strong>[Update]</strong><br/>
  The person from Google who apparently discovered this is called <a href="http://www.caplet.com/" rel="nofollow noreferrer">Mark Miller</a>.</p>
  
  <p>Now I've also read that from <a href="http://www.karmagination.com/blog/2009/07/29/javascript-kung-fu-object-array-and-literals/" rel="nofollow noreferrer">this post</a> that his solution can easily break as well:</p>
  
  <pre><code>// native prototype overloaded, some js libraries extends them
  Object.prototype.toString= function(){
    return  '[object Array]';
  }
  
  function isArray ( obj ) {
    return Object.prototype.toString.call(obj) === '[object Array]';
  }
  
  var a = {};
  alert(isArray(a)); // returns true, expecting false;
  </code></pre>
  
  <p>So, I ask, is there any way that we can truly check for array validity?</p>