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)
相关推荐
浅念-10 分钟前
C++ :类和对象(4)
c语言·开发语言·c++·经验分享·笔记·学习·算法
lly20240614 分钟前
Docker 安装 Python
开发语言
道法自然|~22 分钟前
BugkuCTF栅栏密码解题记录(原理+C语言实现)
c语言·开发语言
chao-Cyril1 小时前
从入门到进阶:前端开发的成长之路与实战感悟
前端·javascript·vue.js
CircleMouse1 小时前
springboot项目中使用Java 8的日期时间API
java·开发语言·spring boot·后端·spring
前端达人1 小时前
被JavaScript忽视的Web Animations API:为什么说它是前端动画的真正未来?
开发语言·前端·javascript·ecmascript
米羊1212 小时前
风险评估文档记录
开发语言·网络·php
摘星编程2 小时前
解锁Agent智能体的未来:五大实战策略彻底革新人机协作模式
java·开发语言
Aerkui2 小时前
Go 泛型(Generics)详解
开发语言·后端·golang