xinggevip

es2015三个点的使用
index.html<!DOCTYPE html> <html lang="en&qu...
扫描右侧二维码阅读全文
10
2019/06

es2015三个点的使用

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<ul id="demo"></ul>



<script>

    let arr = [1,2,3,4,5];
    console.log(...arr);

    function show(...a) {
        console.log(a.sort());
    };
    show(1,2,6,5,4,7,8);

    function show1(a,b,...c) {
        console.log(a,b,c);
    };
    show1(1,2,3,4,5,6,7,8,9);

    // 数组的赋值操作
    // es2015的赋值方式
    let arr1 = [1,2,3,4,5,6,7];
    let arr2 = [...arr1];
    console.log(arr1,arr2);
    // 传统的数组赋值方式
    let arr3 = Array.from(arr1);
    console.log(arr3);

</script>
</body>
</html>

运行结果

1 2 3 4 5
 (7) [1, 2, 4, 5, 6, 7, 8]
 1 2 (7) [3, 4, 5, 6, 7, 8, 9]
 (7) [1, 2, 3, 4, 5, 6, 7] (7) [1, 2, 3, 4, 5, 6, 7]
 (7) [1, 2, 3, 4, 5, 6, 7]
Last modification:June 10th, 2019 at 10:36 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment