Array(數組)的使用

來源:互聯網
上載者:User

標籤:style   java   使用   width   os   javascript   

 

 

    

方法

說明

Concat()

串連2個或多個數組,並返回結果

Push()

向數組末尾添加一個或多個元素,並返回新的長度

Reverse()

顛倒數組中元素的順序

Sort()

對數組的元素進行排序

Slice()

從某個已有的數組返回數組選定的元素

toString()

把數群組轉換成字串

Join()

串連

toLocaleString()

把數群組轉換為本地字串,並返回結果

<script type="text/javascript" language="javascript">
 var arr = new Array(3);//建立數組,可以設定大小也可以不設定
 arr[0]="aaa";
 arr[1]="ddd";
 arr[2]="ccc";
 arr[3]="bbb";//自動擴充大小為4
 document.write(arr[3]+"<br>");
 document.write(arr.length+"<br>");//輸出4
 arr.sort();//數組元素進行排序
 document.write("數組中的元素如下:<br>");
 for(var index in arr){
  document.write(arr[index]+"<br>");   
 }
 
 //其他語言數組的下標都是整型,JavaScript中下標可以為其他類型
 var arr = new Array();
 arr["a"] ="abc";
 arr["b"] ="cba";
 document.write(arr["b"]+"<br>");//輸出cba
 
 //JavaScript中數組是用[],其他語言是用{}
 var arr = ["aa","bb","cc"];
 document.write(arr[1]);
</script>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.