Posted By

anagaiyahoocom on 07/03/11



Versions (?)

Check if javascript object is an Array

 / Published in: JavaScript

This will check if object is an array object.

This will add isArray() method to Array native object. Can be used to check if passed in object is an array. Future ecmascript 5 will have this included. Can use this in the meantime.

Using instanceof Array does not work in certain versions of IE.


var arr = [1,2,3];

alert(Array.isArray(arr)); //displays as true

  1. if(typeof Array.isArray==="undefined") {
  2. Array.isArray = function(arg) {
  3. return "[object Array]";
  4. };
  5. }

Report this snippet  

You need to login to post a comment.