遨翔在知識的海洋裡----js(陣列常用函式)

遨翔在知識的海洋裡發表於2018-03-26
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <!-- <script>
        var arr = new Array(3)

        arr[0] = "jie";
        arr[1] = "biao";
        arr[2] = "nine";

        console.log(arr.length);  3
        arr.length = 5;
        console.log(arr.length);  5
    </script> -->

    <script>
        // var a = [1,2,3];
        // console.log(a.concat(4,5)); 1,2,3,4,5


        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // var arr2 = new Array(3)
        // arr2[0] = "jiee";
        // arr2[1] = "biaoo";
        // arr2[2] = "ninee";
        // console.log(arr1.concat(arr2)) jie,biao,nine,jiee,biaoo,ninee


        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // var arr2 = new Array(3)
        // arr2[0] = "jiee";
        // arr2[1] = "biaoo";
        // arr2[2] = "ninee";
        // var arr3 = new Array(2)
        // arr3[0] = "William"
        // arr3[1] = "Franklin"
        // console.log(arr1.concat(arr2,arr3)) jie,biao,nine,jiee,biaoo,ninee,William,Franklin

    </script>

    <script>
        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // var test = arr1.join() jie,biao,nine
        // console.log(test)

        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // var test = arr1.join(".") jie.biao.nine
        // console.log(test)

        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // var test = arr1.join(" ") jie biao nine
        // console.log(test)
    </script>

    <script>
        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";

        // console.log(arr1)  jie,biao,nine
        // console.log(arr1.pop())   nine
        // console.log(arr1) jie,biao
    </script>

    <script>
        // var arr1 = new Array(3) 
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
 
        // console.log(arr1);  jie,biao,nine
        // console.log(arr1.push("wei")); 4
        // console.log(arr1); jie,biao,nine,wei
    </script>

    <script>
        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // console.log(arr1);  jie,biao,nine
        // console.log(arr1.reverse())  nine,biao,jie
    </script>

    <script>
        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";

        // console.log(arr1); jie,biao,nine
        // console.log(arr1.shift()); jie
        // console.log(arr1); biao,nine
    </script>

    <script>
        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // arr1[3] = "wei";

        // console.log(arr1) jie,biao,nine
        // console.log(arr1.slice(1)) biao,nine
        // console.log(arr1.slice(2,4)) nine
        // console.log(arr1)  jie,biao,nine
    </script>

    <script>
        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // arr1[3] = "wei";

        // console.log(arr1.sort()) biao,jie,nine,wei

        // var arr1 = new Array(3)
        // arr1[0] = "1";
        // arr1[1] = "10";
        // arr1[2] = "1000";
        // arr1[3] = "45";

        // console.log(arr1.sort()) 1,10,1000,45

        // function sortFn(a,b){
        //     return a-b
        // }
        // console.log(arr1.sort(sortFn)) 1,10,45,1000
    </script>

    <script>
        var arr1 = new Array(3)
        arr1[0] = "jie";
        arr1[1] = "biao";
        arr1[2] = "nine";
        arr1[3] = "wei";
        // arr1.splice(2,0,"ninee")  jie,biao,ninee,nine
        // arr1.splice(2,1,"ninee") jie,biao,ninee
        arr1.splice(2,3,"ninee") //jie,biao,ninee
        console.log(arr1)

    </script>

    <script>
        // var arr1 = new Array(3)
        // arr1[0] = "jie";
        // arr1[1] = "biao";
        // arr1[2] = "nine";
        // arr1[3] = "wei";

        // console.log(arr1.toString()) jie,biao,nine,wei
    </script>
</body>

</html>
複製程式碼

相關文章