JavaScript語言基礎7,javascript語言

來源:互聯網
上載者:User

JavaScript語言基礎7,javascript語言

JavaScript中的數組是個新概念。

我們可以使用new關鍵字和Array()建構函式來說明一個 數組:

<HTML><HEAD><TITLE>Hello World</TITLE></HEAD><BODY BGCOLOR="WHITE"><SCRIPT Language="JavaScript" TYPE="text/javascript">var arrayValue1=new Array();arrayValue1[0]="a";arrayValue1[1]="b";document.write("arrayValue1[0]="+arrayValue1[0]+"<BR>");document.write("arrayValue1[1]="+arrayValue1[1]+"<BR>");var arrayValue2=new Array("a","b");document.write("arrayValue2[0]="+arrayValue2[0]+"<BR>");document.write("arrayValue2[1]="+arrayValue2[1]+"<BR>");var arrayValue3=new Array(5);arrayValue3[0]="a";arrayValue3[1]="b";document.write("arrayValue3[0]="+arrayValue3[0]+"<BR>");document.write("arrayValue3[1]="+arrayValue3[1]+"<BR>");</SCRIPT></BODY></HTML>

從上面可知定義一個一維數組的幾種方式,比如定義時指定了數組內容、指定了數組有多少個元素、定義完後進行賦值。

二維數組類似一維數組:

<HTML><HEAD><TITLE>Hello World</TITLE></HEAD><BODY BGCOLOR="WHITE"><SCRIPT Language="JavaScript" TYPE="text/javascript">var arrayValue=new Array();arrayValue[0]=new Array();arrayValue[0][0]="a";arrayValue[0][1]="b";document.write("arrayValue[0][0]="+arrayValue[0][0]+"<BR>");document.write("arrayValue[0][1]="+arrayValue[0][1]+"<BR>");arrayValue[1]=new Array("a","b");arrayValue[1][0]="c";arrayValue[1][1]="d";document.write("arrayValue[1][0]="+arrayValue[1][0]+"<BR>");document.write("arrayValue[1][1]="+arrayValue[1][1]+"<BR>");</SCRIPT></BODY></HTML>

定義二維數組時,我們得知在JavaScript中只支援一維數組,不存在多維陣列,JavaScript允許把一個數組的元素宣告成一個數組,用來類比出多維陣列。



轉載請註明出處:http://blog.csdn.net/hai_qing_xu_kong/article/details/40934835    情緒控_ 


聯繫我們

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