当前位置: 首页 > news >正文

JavaScript 对象判断

如何判断一个对象是否是Set、Map、Array、Object
参考链接:
https://blog.csdn.net/yunchong_zhao/article/details/115915624

let set = new Set()
let map = new Map()
let arr = []
let obj = {}console.log(Object.prototype.toString.call(obj)); // [object Object]
console.log(Object.prototype.toString.call(arr)); // [object Array]
console.log(Object.prototype.toString.call(set)); // [object Set]
console.log(Object.prototype.toString.call(map)); // [object Map]console.log(set.constructor == Set); // true
console.log(map.constructor == Map); // true
console.log(arr.constructor == Array); // true
console.log(obj.constructor == Object); // trueconsole.log("-------------------");console.log(Set.prototype.isPrototypeOf(set)); // true
console.log(Array.prototype.isPrototypeOf(arr)); // true
console.log(Object.prototype.isPrototypeOf(obj)); // true
console.log(Map.prototype.isPrototypeOf(map)); // trueconsole.log("-------------------");console.log(set instanceof Set); // true
console.log(arr instanceof Array); // true
console.log(map instanceof Map); // true
console.log(obj instanceof Object); // trueconsole.log("-------------------");console.log(set.__proto__ === Set.prototype); // true
console.log(map.__proto__ === Map.prototype); // true
console.log(obj.__proto__ === Object.prototype); // true
console.log(arr.__proto__ === Array.prototype); // true
http://www.lryc.cn/news/301722.html

相关文章:

  • Android下SF合成流程重学习之onMessageInvalidate
  • 基于SpringBoot+WebSocket+Spring Task的前后端分离外卖项目-订单管理(十七)
  • 【Java多线程进阶】JUC常见类以及CAS机制
  • Python算法100例-1.7 最佳存款方案
  • ADO世界之FIRST
  • 【COMP337 LEC 5-6】
  • 力扣72. 编辑距离(动态规划)
  • linux tree命令找不到:如何使用Linux Tree命令查看文件系统结构
  • OJ_最大逆序差
  • MyBatis-Plus 实体类里写正则让字段phone限制为手机格式
  • K8S之运用污点、容忍度设置Pod的调度约束
  • Sora爆火,普通人的10个赚钱机会
  • 【C++】C++入门—初识构造函数 , 析构函数,拷贝构造函数,赋值运算符重载
  • 沁恒CH32V30X学习笔记04--外部中断
  • 基础IO[三]
  • Leetcode 392 判断子序列
  • 基于微信小程序的校园跑腿系统的研究与实现,附源码
  • VTK Python PyQt 监听键盘 控制 Actor 移动 变色
  • 力扣 第 124 场双周赛 解题报告 | 珂学家 | 非常规区间合并
  • 2024年华为OD机试真题-生成哈夫曼树-Java-OD统一考试(C卷)
  • 【实战】二、Jest难点进阶(二) —— 前端要学的测试课 从Jest入门到TDD BDD双实战(六)
  • (一)【Jmeter】JDK及Jmeter的安装部署及简单配置
  • HAL/LL/STD STM32 U8g2库 +I2C SSD1306/sh1106 WouoUI磁贴案例
  • 手机如何改自己的ip地址
  • ajax函数库axios基本使用
  • 【nginx实践连载-4】彻底卸载Nginx(Ubuntu)
  • 究极小白如何自己搭建一个自动发卡网站-独角数卡
  • Java_方法(重载方法签名等详解)
  • VQ35 评论替换和去除(char_length()和replace函数的使用)
  • 【MySQL】学习多表查询和笛卡尔积