• ES6笔记③


    1.查找关键字  includes(); 返回布尔值

    //①:includes -->代替-->indexof-->返回布尔值
        var str = "769909303";
        console.log(str.indexOf("9"));//2
        console.log(str.includes("9"));//true

    2. 重复字符 repeat();

    //②:repeat -->重复
        console.log('meow'.repeat(3));

    3.模块字符串 3个特性: ①:特殊字符再也不用转义了。 ②:变量拼接 + 换行拼接 ③:支持表达式

    //3. 模板字符串 --> 对字符串中的特殊字符,再也不用转义了
                var text = "This string contains "double quotes" which are escaped.";
                    console.log(text);            
                var text2 =    `This string contains "double quotes" which are escaped.`;    
                    console.log(text2);
    //拼接变量语法: ``+${};  
    const name = 'Tiger';
    const age = 13;
    console.log(`My cat is named ${name} and is ${age} years old.`);
    //换行拼接
    let text = ( `cat
      dog
      nickelodeon`
     );
    //支持表达式
    let today = new Date();
    let text = `The time and date is ${today.toLocaleString()}`;

    4.结构--> 更方便拿到数组、对象中的值。注意:等号两边都不限制个数,像创建变量一样,默认为undefined。对象解构时,变量名要同对象名

    //不限制个数
    var
    arr = [0,1,2,3,4,5,6,7,8,9]; var [a,b,c,d] = [arr[0],1,2,3,4]; console.log(a);
    var obj = {a:10,b:20};
    var {a,b,c} = obj;
          console.log(a);

    /*[创建一个关联变量数组或变量对象,挨个赋值嘛]*/

    5.创建函数时,初始化默认值 ES6写法

    function fun(x=0,y=0){
        return x+y;
    }
    console.log(fun(5));//5
    console.log(fun(5,10));//15

    6.更简洁的合并数组  ...自定义剩余参数

    var arrreat  = [5,6];
    var news = [1,2,3,4,...arrreat,7];
    console.log(news);//1234567
  • 相关阅读:
    mysql 触发器
    监听mac价格变动,降价了就通知。
    mysql 索引、约束
    mysql 三种insert插入语句
    idea 控制台中文乱码
    go 刷算法第三题——二叉树根节点到叶子节点和为指定值的路径
    mysql 排序序号sql+斐波那契统计
    go 刷算法第二题——最长回文子串
    常见排序算法-基数排序、计数排序
    常见排序算法-选择、冒泡排序
  • 原文地址:https://www.cnblogs.com/-ooo-/p/5748929.html
Copyright © 2020-2023  润新知