JavaScript Array數組對象

來源:互聯網
上載者:User

標籤:倒數   type   轉換   str   for   不同   eof   長度   func   

<DOCTYPE html><html><head>    <title>數組</title></head><body>    <script type="text/javascript">    //1.無參建構函式,建立一空數組        // var a1=new Array(1,2,3,4);         //document.write(a1)    var a = new Array();        a[0] = "1趙曉龍";        a[1] = "2趙曉龍";        a[2] = 3;        for(var i=0;i<a.length;i++){            // document.write(a[i]);            // document.write("<br>");            }            // document.write("<hr>");        //使用 for...in 聲明來迴圈輸出數組中的元素        for (hehe in a){            //document.write(a[hehe]);             //document.write("<br>");        }         //document.write("<hr>");    // 合并數組  concat(合并)    var arr = new Array()        arr[0] = "hello"        arr[1] = "word"        arr[2] = "name"        //document.write(arr.concat());    //document.write("<hr>");    // 數組合并字串 join("")    //document.write(arr.join(""));    //document.write("<br>");    // 給數組值排序    function sortNumber(a,b)        {        return a - b        }        var arr = new Array(6)        arr[0] = "10"        arr[1] = "5"        arr[2] = "40"        arr[3] = "25"        arr[4] = "1000"        arr[5] = "1"        //document.write(arr.sort(sortNumber))        // 更改數組中的值        arr[5]="Opel";        //document.write(arr[5])        //刪除數組中最後一個值        var a = new Array()        a[0] = "hello"        a[1] = "aword"        a[2] = "name"        //document.write(a.pop())        //9.給數組加一個新的數組時;    並返回新的長度。        //document.write(a.push("James") + "<br />")        //document.write(a)        //顛倒數組中元素的順序。        //document.write(a.reverse())        //使用 shift() 刪除並返回數組的第一個元素。        //document.write(a.shift() + "<br />")        //使用slice()選取第幾個數組並輸出值        //document.write(a.slice(1) + "<br />")        //對數組進行排序        //document.write(a.sort())        //把數群組轉換為字串        //document.write(a.toString())        //把數群組轉換為本地數組,並返回結果。        //document.write(a.toLocaleString())        //給字串開頭添加一個數值        //a.unshift("William")        //toString()和valueOf()的主要不同點在於,toString()返回的是字串,而valueOf()返回的是原對象        //document.write(a)    </script></body></html>

 

JavaScript Array數組對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.