美文网首页
ES6学习-1

ES6学习-1

作者: 云飞f | 来源:发表于2018-07-16 16:12 被阅读0次

    声明变量使用 let , const


    解构赋值:

    let [a,b,c] = [1,2,3];

    let [a,[b,c]]=[1,[2,3]];

    let [a,b,c="默认值"] = [1,2];

    let json ={name:"张三", age:18};

    {name,age} = json; 可直接取出name,age

    {name:n,age:g} = json; 可取别名

    保持左右两边结构一致

    let a = 5; let b = 10; 

    [a,b] =[b,a];

    两数交换


    字符串连接

    let name="张三";

    `你的名字叫${name}`


    字符串查找

    let str ="abcdefg";

    str.includes("def"); 返回T/F 区分大小写

    字符串以XX开头 startsWith("")  

    字符串以XX结尾endsWith("")

    重复字符串

    let str ="a";console.log(str.repeat(3)); 重复输出3次

    填充字符串

    str.padStart(总长度, 填充东西) 往前填充

    str.padEnd(总长度, 填充东西)  往后填充


    函数默认值


    扩展运算符

    function show()

        {

            console.log(Array.prototype.slice.apply(arguments).sort()); 数组排序

            console.log(Array.prototype.slice.call(arguments).sort()); 数组排序

        }

    function show(...a)

        {

              console.log(a.sort());  //数组排序

        }

    show(1,2,3,4,65,-3);

    拷贝数组

    let array = [1,2,3];

        let array2 =[...array];

        let array3 = Array.from(array);

        console.log(array);

        console.log(array2);

        console.log(array3);

    箭头函数

    两者相同

    箭头函数中的this

    箭头函数中没有 arguments

    相关文章

      网友评论

          本文标题:ES6学习-1

          本文链接:https://www.haomeiwen.com/subject/tgcbpftx.html