최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday

티스토리 뷰

자바스크립트 2차원배열 선언하고 쓰기

 

<!DOCTYPE HTML>
<html lang="ko">
<head>
<title> NewDocument </title>
<meta charset="utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
</head>
<body>
	<script>
		//2차원 배열 선언1
		var myArr = new Array();
			myArr[0] = new Array("0-0", "0-1");
			myArr[1] = new Array("1-0", "1-1");
			myArr[2] = new Array("2-0", "2-1");
		console.log(myArr[1][0]); //1-0
		console.log(myArr[2][1]); //2-1
		
		//2차원 배열 선언2
		var myArr2 = [];
			myArr2[0] = ["0-0","0-1"];
			myArr2[1] = ["1-0","1-1"];
			myArr2[2] = ["2-0","2-1"];
		console.log(myArr2[1][0]); //1-0
		console.log(myArr2[2][1]); //2-1

		//2차원 배열 선언3
		var myArr3 = [];
		for(var i=0; i<3; ++i)
		{
			myArr3[i] = [String(i+"-"+0), String(i+"-"+1)];
		}
		console.log(myArr3[1][0]); //1-0
		console.log(myArr3[2][1]); //2-1
	</script>
</body>
</html>

 

 결과 




댓글