博客
关于我
深拷贝和类型检测
阅读量: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/

你可能感兴趣的文章
python %ns的作用
查看>>
Python + Appium 之 APP 自动化测试,坑点汇总!(建议收藏)
查看>>
Python + Appium 自动化操作微信入门(超详细)
查看>>
Python + Pytest 自动化框架的用例依赖实操
查看>>
python进阶(8):yield函数
查看>>
Python + requests实现接口自动化测试!
查看>>
python + requests实现的接口自动化测试(超详细~)
查看>>
Python + selenium 如何截图?
查看>>
Python + Selenium 登录QQ邮箱
查看>>
Python + selenium如何做接口自动化测试?
查看>>
Python + selenium如何截图!
查看>>
Python + selenium自动化生成测试报告!
查看>>
Python - C 嵌入式分段错误
查看>>
Python - DM 一个用户 Discord 机器人
查看>>
python - Flask 基础 - 蓝图( Blueprint )(2)
查看>>
python - os.getenv 和 os.environ 看不到我的 bash shell 的环境变量
查看>>
Python - while循环
查看>>
Python - “if“中的逻辑评估顺序陈述
查看>>
Python - 从 Google Cloud Storage 下载整个目录
查看>>
Python - 使用 pandas 格式化 Excel 单元格
查看>>