美文网首页
JavaScript怎么判断一个数组是数组呢?

JavaScript怎么判断一个数组是数组呢?

作者: 六寸光阴丶 | 来源:发表于2020-03-26 21:50 被阅读0次

写在前面

如果本文对您有所帮助,就请点个关注吧!

解决方案

方法一:instanceof

variable instanceof Array

方法二:原型prototype + toString + call

Object.prototype.toString.call(variable).indexOf('Array') !== -1;

方法三:原型prototype + isPrototypeOf()方法

Array.prototype.isPrototypeOf(variable) 

方法四:构造函数 constructor

variable.constructor.toString().indexOf("Array") !== -1

方法五:数组方法 isArray()

Array.isArray(variable);

相关文章

网友评论

      本文标题:JavaScript怎么判断一个数组是数组呢?

      本文链接:https://www.haomeiwen.com/subject/kgvhuhtx.html