当前位置: 首页>编程语言>正文

Javascript-判断一个数据是否为数组的方法

instanceOf

let a = []; console.log(a instanceof Array) //true

Array.isArray

let d = [7,8,9];
console.log(Array.isArray(d))  //true

constructor

let b = [7,8,9];
console.log(b.constructor === Array)  //true

Object.prototype.toString.call()

let c = [7,8,9];
console.log(Object.prototype.toString.call(c))  //[Object Array]



https://www.xamrdz.com/lan/5pa1963013.html

相关文章: