let a = [1, 2, 3];
// 方法一:Array.isArray()
console.log(Array.isArray(a));
// 方法二:Array.prototype.isPrototypeOf()
console.log(Array.prototype.isPrototypeOf(a));
// 方法三:constructor
console.log(a.constructor.toString().indexOf('Array'));
// 方法四:Object.prototype.toString.call()
console.log(Object.prototype.toString.call(a));
JavaScript判断变量是不是数组
最新推荐文章于 2024-06-05 18:36:51 发布