YAN-YEN

判断给定的对象是不是数组的四个方法

  1. instanceof方法
    判断一个对象是否在其原型链原型构造函数的属性
  2. constructor方法
    constructor属性返回创建此对象的构造函数
  3. Object.prototype.toString.call(xxx)
  4. isArray()
const arr = []
console.log(arr instanceof Array)
console.log(arr.constructor === Array)
console.log(Object.prototype.toString.call(arr)==="[object Array]")
console.log(Array.isArray(arr))

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2021-11-27
猜你喜欢
  • 2022-02-09
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案