博客
关于我
深拷贝和类型检测
阅读量: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 最强 IDE 详细使用指南!
查看>>
Python 有一个不可变的列表吗?
查看>>
Python 机器学习入门之 pandas 的使用
查看>>
Python 机器学习实战
查看>>
python 杀死子进程_subprocess.popen.kill杀死所有子进程
查看>>
Python 条件语句与循环结构详解
查看>>
Python 条件运算符解决方法如何工作?
查看>>
python 枚举类型
查看>>
Python 查询 Mongodb数据库
查看>>
python 查询Neo4j多节点的多层关系
查看>>
python多处理参数:深拷贝?
查看>>
Python多处理使用队列写入同一个文件
查看>>
Python多处理.Process:从局部变量开始
查看>>
Python多处理-进程数
查看>>
python多个定时器_python单线程实现多个定时器示例
查看>>
python处理文本_Python - Tokenization
查看>>
Python处理数据方向之OpenCV
查看>>
python处理一亿条数据_Python数据分析实战(一)
查看>>
Python处理PDF神器:PyMuPDF的安装与使用
查看>>
Python处理Excel数据
查看>>