Use variable as the array index : Array Index « Array « JavaScript Tutorial






<html>
<head>
<title>A Simple Page</title>
<script language="javascript">
<!--
var days_of_week = new Array(7);
days_of_week[0] = "Sunday";
days_of_week[1] = "Monday";
days_of_week[2] = "Tuesday";
days_of_week[3] = "Wednesday";
days_of_week[4] = "Thursday";
days_of_week[5] = "Friday";
days_of_week[6] = "Saturday";
var x = 2;
alert(days_of_week[x]);
//  -->
</script>
</head>
<body>

</body>
</html>








11.3.Array Index
11.3.1.Reference array value by index
11.3.2.Use variable as the array index
11.3.3.Append elements to Array by using the index
11.3.4.Use for each loop to assign array element value
11.3.5.Reference array element by random index value