HTML and CSS Reference
In-Depth Information
EXAMPLE 9.8 ( CONTINUED )
2
for (var i=0; i < grades.length; i++) {
3
for (var j=0; j < grades[i].length; j++) {
document.write(
4
"<td bgcolor='#fff00'>"+ grades[i][j] + "</td>");
}
5
document.write("</tr>");
}
</script>
</table>
</body>
</html>
EXPLANATION
1
A two-dimensional array (array of arrays) is created using the literal notation. The
outer set of square brackets surrounds the set of rows nested within them. Each
nested row is enclosed in its own set of square brackets and each row separates
with a comma (see Figure 9.11).
2
This outer for loop will cycle through each row. The length property determines
the size of the row, which is 3.
3
The nested for loop is used to cycle through each of the elements in a row.
4
The two index values represent the rows, i , and its element, j , respectively.
5
The </tr> tag closes the table row.
Figure 9.11 Two-dimensional array.
A Key in an Associative Array with More Than One Value. It is possible that
the key of an associative array is associated with more than one value. To accomplish
this, rather than a single value, a new array object is assigned as a set of values, as shown
in Example 9.9.
 
Search WWH ::




Custom Search