javascript解决IE8一下浏览器不支持isArray属性的兼容性问题

语法:Array.isArray(object)

作用:测试对象是否为数组

参数:object:必须。需要测试的对象

返回值:如果object是数组,则为true,否则返回false。如果参数objet参数不是对象,则返回false。

方法一:

if(!Array.isArray){

  Array.isArray=function(obj){

        return Array.prototype.isprototype(obj);

     }

}

方法二:

if(!"isArray" in Array){

  Array.isArray=function(obj){

   return obj instanceof Array;
      }

}

方法三:

if(Array.isArray!==undefined){

  Array.isArray=function(obj){

    return obj.constructor==Array;
  }

}

方法四:

if(!Array.isArray){

  Array.isArray=function(obj){

    return Object.prototype.toString.call(obj)=="[object Array]";
  }

}

猜你喜欢

转载自www.cnblogs.com/mchtig/p/9267601.html