JS常见问题

文章目录

如何判断是数组

  1. Array.isArray
    console.log(Array.isArray(arr))
  2. instanceof(instanceof 运算符用于验证构造函数的 prototype 属性是否出现在对象的原型链中的任意位置)
    console.log(arr1 instanceof Array)
  3. constructor(实例的构造函数属性constructor指向构造函数)
    console.log(arr.constructor === Array)
  4. Object.prototype.toString.call()
    Object.prototype.toString.call(arr) === '[object Array]');
  5. 原型链
    arr.__proto__ === Array.prototype
  6. Array.prototype.isPrototypeOf(isPrototypeOf用于判断 一个对象是否是另一个对象的原型)
    Array.prototype.isPrototypeOf(arr)
相关推荐
Lao乾妈官方认证唯一女友:D16 分钟前
通过plasmo的wallet扩展添加新钱包
javascript·web3·区块链
MediaTea17 分钟前
Python:collections.Counter 常用函数及应用
开发语言·python
ALKAOUA24 分钟前
力扣面试150题刷题分享
javascript·笔记
LawrenceLan39 分钟前
37.Flutter 零基础入门(三十七):SnackBar 与提示信息 —— 页面反馈与用户交互必学
开发语言·前端·flutter·dart
李昊哲小课40 分钟前
Python json模块完整教程
开发语言·python·json
易醒是好梦40 分钟前
Python flask demo
开发语言·python·flask
swipe1 小时前
JavaScript 对象与属性描述符:从原理到实战
前端·javascript·面试
&活在当下&1 小时前
Vue3 h函数用法详解
前端·javascript·vue.js