码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript语言基础7

时间:2014-11-09 01:03:11      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:javascript   web   脚本   html   web前端   

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>
bubuko.com,布布扣
从上面可知定义一个一维数组的几种方式,比如定义时指定了数组内容、指定了数组有多少个元素、定义完后进行赋值。

二维数组类似一维数组:

<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>
bubuko.com,布布扣
定义二维数组时,我们得知在JavaScript中只支持一维数组,不存在多维数组,JavaScript允许把一个数组的元素声明成一个数组,用来模拟出多维数组。



转载请注明出处:http://blog.csdn.net/hai_qing_xu_kong/article/details/40934835    情绪控_ 


JavaScript语言基础7

标签:javascript   web   脚本   html   web前端   

原文地址:http://blog.csdn.net/hai_qing_xu_kong/article/details/40934835

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!