博客
关于我
深拷贝和类型检测
阅读量:744 次
发布时间:2019-03-22

本文共 720 字,大约阅读时间需要 2 分钟。

// 深拷贝        var user1 = {name: "小明", age: 18, deMent: {bumen: "市场部", no: "001"}};         var user2 = JSON.stringify(user1);        var user3 = JSON.parse(user2);        user3.age = 40;        user3.deMent.no = "999";        console.log(user1); // 输出: {name: "小明", age: 18, deMent: {bumen: "市场部", no: "001"}}        console.log(user3); // 输出: {name: "小明", age: 40, deMent: {bumen: "市场部", no: "999"}}     // 深拷贝的实现步骤    1. 使用 JSON.stringify 将目标对象转换为字符串    2. 使用 JSON.parse 解析字符串生成新对象    3. 对于对象中的嵌套对象等深层结构,新对象会生成独立的新实例        // 数据类型检测    - 基本数据类型使用 typeof 来检测    - 引用数据类型使用 instanceof 检测    - 检测数组时使用 Array.isArray(arr) 方法

 

// 代码示例        var arr = [1, 2, 3, 4, , 5];        console.log(Array.isArray(arr)); // 输出: true

 

转载地址:http://cmwwk.baihongyu.com/

你可能感兴趣的文章
python2备份交换机配置脚本
查看>>
Python3 - 在字符串格式化程序参数中使用变量
查看>>
Python3 A*寻路算法实现
查看>>
python3 grpc安装
查看>>
python3 mysql 封装多表_python3 mysql-多表查询
查看>>
python3 mysql8_Python MySQL8.0 错误:authentication plugin 'calling_sha2_password' is not supported....
查看>>
Python关键代码总览!从Zero到Hero必看的考点
查看>>
python3 robotframework+pycharm框架搭建
查看>>
Python3 shutil模块
查看>>
Python关于strftime函数详细解析 附实战代码
查看>>
Python3 tutorial day3
查看>>
python3 week4
查看>>
Python3 创建数组
查看>>
python3 套接字异常(a byte-like object is required not str)
查看>>
python3 实现用户三次输入错误记录黑名单并对该用户登录锁定-day1
查看>>
python3 文本变图片
查看>>
Python3 查看 com 组件的属性
查看>>
python3 案例分享--发邮件
查看>>
python3 模板库_Python3 标准库概览_Python教程_我爱模板网 - 提供下载各种免费建站资源,免费网站模板,免费网页特效,让你爱上建站!...
查看>>
Python3 求最大/小值及索引值 Numpy
查看>>