Multi-Dimension Arrays
Arrays are not just limited to single dimension and can have
a maximum of 60 dimensions. Two-dimension arrays are the most commonly used ones.
Example
In the following example, a multi-dimension array is declared with 3 rows and 4 columns.
<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
Dim arr(2,3) ' Which has 3 rows and 4 columns
arr(0,0) = "Apple"
arr(0,1) = "Orange"
arr(0,2) = "Grapes"
arr(0,3) = "pineapple"
arr(1,0) = "cucumber"
arr(1,1) = "beans"
arr(1,2) = "carrot"
arr(1,3) = "tomato"
arr(2,0) = "potato"
arr(2,1) = "sandwitch"
arr(2,2) = "coffee"
arr(2,3) = "nuts"
document.write("Value in Array index 0,1 : " & arr(0,1) & "<br />")
document.write("Value in Array index 2,2 : " & arr(2,2) & "<br />")
</script>
</body>
</html>
When the above code is saved as .HTML and executed in Internet
Explorer, it produces the following result:
Value stored in Array index : 0 , 1 : Orange
Value stored in Array index : 2 , 2 : coffee
No comments:
Post a Comment