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)
相关推荐
2401_832131952 分钟前
模板编译期机器学习
开发语言·c++·算法
嵌入小生0072 分钟前
Data Structure Learning: Starting with C Language Singly Linked List
c语言·开发语言·数据结构·算法·嵌入式软件
子春一6 分钟前
Flutter for OpenHarmony:构建一个专业级 Flutter 节拍器,深入解析定时器、状态同步与音乐节奏交互设计
javascript·flutter·交互
独自破碎E7 分钟前
LCR005-最大单词长度乘积
java·开发语言
2401_838472518 分钟前
单元测试在C++项目中的实践
开发语言·c++·算法
naruto_lnq14 分钟前
移动语义与完美转发详解
开发语言·c++·算法
梦想画家20 分钟前
掌控并发的灵魂:Go context 从入门到实战全解析
开发语言·golang
Aotman_22 分钟前
Vue <template v-for> key should be placed on the <template> tag.
前端·javascript·vue.js
yunsr32 分钟前
python作业1
开发语言·python·算法
摘星编程32 分钟前
在OpenHarmony上用React Native:自定义useTranslation翻译功能
javascript·react native·react.js