配列

[書き方]

意味は全て同じである。

var array = ["みかん" , "カルビ"];

var array = new Array();
	array[0] = "みかん";
	array[1] = "カルビ";

var array = new Array("みかん" , "カルビ");

var array = Array("みかん" , "カルビ");

var array = [];
	arary[0] = "みかん";
	arary[1] = "カルビ";
	
var array = {0 : "みかん" , 1 : "カルビ"};

[実行結果]

[ソースコード]

<script type="text/JavaScript">
	var hairetsu1 = new Array();
		hairetsu1[0] = 1;
		hairetsu1[1] = 2;
		hairetsu1[2] = 3;
	document.getElementById('hairetsu1').innerHTML = hairetsu1;
	
	var hairetsu2 = new Array(4,5,6);
	document.getElementById('hairetsu2').innerHTML = hairetsu2;
	
	var hairetsu3 = [7,8,9];
	document.getElementById('hairetsu3').innerHTML = hairetsu3;
	
	var hairetsu4 = new Array(3);
		hairetsu4[0] = 10;
		hairetsu4[1] = 11;
		hairetsu4[2] = 12;
	document.getElementById('hairetsu4').innerHTML = hairetsu4;
</script>

詳しくはコチラ

インデックスにもどる