zoukankan      html  css  js  c++  java
  • ES6-扩展运算符和rest运算符

    es6-扩展运算符和rest运算符

    扩展运算符:不确定他的参数个数时使用运算扩展符

    // 声明一个方法 但不确定他的参数个数时使用对象运算扩展符
    function ananiha(...arg){
            console.log(arg[0]); //1
            console.log(arg[1]); //2
            console.log(arg[2]); //3
            console.log(arg[3]); //undefined
    }
    ananiha(1,2,3);
    
    // 例子
    let arr1 = ['www','anan','com'];
    let arr2 = arr1;    //不开辟新的内存空间 把arr2的内存空间映射到了arr1
    console.log(arr2);
    
    arr2.push('roger');
    console.log(arr1);
    
    // 用扩展运算符去解决
    let arr1 = ['www','anan','com'];
    let arr2 = [...arr1]; //赋值arr1中的每一个值 
    console.log(arr2); //没有改变
    
    arr2.push('roger');
    console.log(arr2); //改变了
    console.log(arr1);  //没有改变
    rest运算符:
    // rest运算符
    // rest...
    //rest 英文翻译:剩余
    
    function anan(first,...arr){
        // console.log(arr.length);
        // for of 循环提高效率
        for(let val of arr){
            console.log(val);
        }
    }
    anan(1,3,4,5,6,8); // 5  打印出来我们不确定的参数的length
  • 相关阅读:
    spring MVC配置详解
    使用JDBC连接各种数据库
    Linux Shell常用shell命令
    IOS返回go(-1)
    NFS客户端挂载
    oracle常用函数
    支付宝手机网站支付流程(Node实现)
    SQL中的case when then else end用法
    mysql
    socket
  • 原文地址:https://www.cnblogs.com/Ananiah/p/11067601.html
Copyright © 2011-2022 走看看