We would like to know how to iterate through multidimensional array using key values.
<!DOCTYPE html>
<html>
<body>
<script>
var array = [
[1,2,3],<!--from w w w.j a v a 2 s . c om-->
[101,102,103]
];
for (var i=0; i<array.length; ++i) {
var subArray = array[i];
for (var j=0; j<subArray.length; ++j) {
document.writeln(subArray[j]);
document.writeln('<br/>');
}
}
array.forEach(function(item, i) {
item.forEach(function(subItem, i) {
document.writeln(subItem);
document.writeln('<br/>');
});
});
</script>
</body>
</html>
The code above is rendered as follows: