zoukankan      html  css  js  c++  java
  • 扩展运算符... 的使用

    // 1、合并数组
    let arr1 = [1,2,3];
    let arr2 = [4,5]
    let arr3 = [...arr1,...arr2];
    
    console.log(arr3); //[1, 2, 3, 4, 5]
    console.log([...arr1,...arr2]);//[1, 2, 3, 4, 5]
    
    
    let arrA = [1,2,3];
    let arrB = [4,5,...arrA];
    let arrC = [...arrA,4,5];
    
    console.log(arrB,arrC); // [4, 5, 1, 2, 3]   [1, 2, 3, 4, 5]
    
    // 2、合并对象
    let obj = { a:1,b:2 };
    let obj2 = { ...obj };
    console.log(obj2)
    //{ a: 1, b: 2 }
    console.log(obj == obj2)
    
    //3、函数传值
    function fn(a,b,c){
        console.log(a)
        console.log(b)
        console.log(c)
    }
    
    
    let arr = [1,2,3];
    //ES6
    fn(...arr);
    
    // 4、配合解构使用
    let [a,...arr11] = [1,2,3,4,5];
    console.log(a); //1
    console.log(arr11) //[ 2, 3, 4, 5 ]
    
    let {a,...obj} = {a:1, b:"1", c:function(){}, d:null, e:undefined, e:Symbol};
    console.log(a);
    //1
    console.log(obj);
    //{ b: '1', c: [Function: c], d: null, e: [Function: Symbol] }
  • 相关阅读:
    软件测试工具
    Linux笔记
    Google Test
    字典dict()
    元组tuple 可迭代对象
    列表list
    一些总结
    format()
    列表list
    format() expandtabs() 输入表格数据
  • 原文地址:https://www.cnblogs.com/zhangjianhua26/p/15137821.html
Copyright © 2011-2022 走看看