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)
相关推荐
古城小栈7 分钟前
Rust 网络请求库:reqwest
开发语言·网络·rust
hqwest26 分钟前
码上通QT实战12--监控页面04-绘制6个灯珠及开关
开发语言·qt·qpainter·qt事件·stackedwidget
i橡皮擦31 分钟前
TheIsle恐龙岛读取游戏基址做插件(C#语言)
开发语言·游戏·c#·恐龙岛·theisle
哈__38 分钟前
React Native 鸿蒙跨平台开发:PixelRatio 像素适配
javascript·react native·react.js
bing.shao1 小时前
golang 做AI任务执行
开发语言·人工智能·golang
用户6387994773051 小时前
每组件(Per-Component)与集中式(Centralized)i18n
前端·javascript
DarkLONGLOVE1 小时前
Vue组件使用三步走:创建、注册、使用(Vue2/Vue3双版本详解)
前端·javascript·vue.js
DarkLONGLOVE1 小时前
手把手教你玩转Vue组件:创建、注册、使用三步曲!
前端·javascript·vue.js
源代码•宸2 小时前
Golang语法进阶(协程池、反射)
开发语言·经验分享·后端·算法·golang·反射·协程池
basketball6162 小时前
python 的对象序列化
开发语言·python