zoukankan      html  css  js  c++  java
  • 深拷贝和类型检测

          //  深拷贝
            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"}}
    
             // 深拷贝的步骤 JSON.stringify(被拷贝的对象); 把对象转为一个字符串
             // JSON.parse(user2);会根据字符串生成一个新的对象
    
             // 类型检测
             /*
             基本数据类型检测使用typeof来检测    console.log(变量 typeof 基本类型)
             引用数据类型使用instanceof来检测    console.log(函数 instanceof Function)
             */
    
             // 检测数组
             var arr=[1,2,3,4,,5];
             console.log(Array.isArray(arr)); //true
  • 相关阅读:
    php获取文件后缀名格式
    猴子分桃问题2
    猴子吃桃问题1
    判断字符串中字母出现的次数用分割法
    成绩表
    二维数组所有元素求和输出
    冒泡排序
    1.8作业
    1.8
    1.6
  • 原文地址:https://www.cnblogs.com/IwishIcould/p/11566237.html
Copyright © 2011-2022 走看看