You can do something like this:

var cubes = [
 [1, 2, 3],
 [4, 5, 6],    
 [7, 8, 9],
];

for(var i = 0; i < cubes.length; i++) {
    var cube = cubes[i];
    for(var j = 0; j < cube.length; j++) {
        display("cube[" + i + "][" + j + "] = " + cube[j]);
    }
}

Working jsFiddle:

  • http://jsfiddle.net/TRR4n/

The output of the above:

cube[0][0] = 1
cube[0][1] = 2
cube[0][2] = 3
cube[1][0] = 4
cube[1][1] = 5
cube[1][2] = 6
cube[2][0] = 7
cube[2][1] = 8
cube[2][2] = 9
Answer from icyrock.com on Stack Overflow
🌐
CoreUI
coreui.io › blog › how-to-loop-through-a-2d-array-in-javascript
How to loop through a 2D array in JavaScript · CoreUI
August 3, 2024 - To create a two-dimensional array ... console.log(array[i][j]) } } Here, the outer loop traverses the rows of the multidimensional array, while the inner loop traverses the elements within each row....
Discussions

Looping Through Multidimensional Array with Nested Arrays - JavaScript - SitePoint Forums | Web Development & Design Community
Hi all, myArray = [ [["ALBL","BLAL"],["TDBL"],["TDAL"],"ABL"], [["CLDL","DLCL"],["TDDL"],"CDL"], [["ELFL","FLEL"],["TDFL"],"EFL"], ] I am trying to check if a value exists in the first nested array of myArray. For example the value DLCL I’ve tried the following but can’t get it to work ... More on sitepoint.com
🌐 sitepoint.com
0
September 27, 2015
How to loop through & display Javascript Multidimensional Array - Stack Overflow
I have a testing search software and it stores the data in a multidimensional array. I can return the whole database but cannot return just one value. I'm trying to figure out how to return one sec... More on stackoverflow.com
🌐 stackoverflow.com
May 22, 2017
Iterate through multidimensional arrays using for loop
How would you multiply an array like this: [[2,3,[2,3]], [2,3], [2,3]]? I’ve tried this, but it doesn’t work · Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft · That’s the ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
17
0
May 19, 2020
javascript - Loop through multidimensional array - Stack Overflow
How can i loop through the below multidimensional array? I am creating the array like this: var _cQueue = [[]]; And adding items like this: var valueToPush = new Array(); valueToPush['unique_email@ More on stackoverflow.com
🌐 stackoverflow.com
🌐
SitePoint
sitepoint.com › javascript
Looping Through Multidimensional Array with Nested Arrays - JavaScript - SitePoint Forums | Web Development & Design Community
September 27, 2015 - Array.prototype.find = function(query){ for (var index in this){ var value = this[index]; if (typeof(value.find) === 'function'){ if(value.find(query)) { return true; } } if (value == query){ return true; } } return false; }
🌐
freeCodeCamp
forum.freecodecamp.org › t › iterate-through-multidimensional-arrays-using-for-loop › 385021
Iterate through multidimensional arrays using for loop - The freeCodeCamp Forum
May 19, 2020 - Hi, I understand that the code below evaluates multiplication of a simple array var arr = [[2,3],[2,3]]; var product = 1; For (i=0; i<arr.length; i++) { For (j=0; j<arr[i].length; j++) { product *=arr[i][j…
🌐
DEV Community
dev.to › aysha › javascript-before-framework-iterating-through-a-multidimensional-array-using-javascript-22gp
Iterating through a multidimensional array in JavaScript. - DEV Community
May 4, 2023 - For Array 3: Aaron has an index of 0, and Dariella has an index of 1. Iterating through multidimensional arrays means repeating the same functions for every value present within the array present in a super-array.
Find elsewhere
🌐
CodeSignal
codesignal.com › learn › courses › multidimensional-arrays-and-their-traversal-in-javascript › lessons › more-ways-to-traverse-multidimensional-arrays-in-javascript
More Ways to Traverse Multidimensional Arrays in JavaScript
We can leverage the utility of JavaScript's for loop to traverse a 2D matrix in reverse order. This flexibility can also create a sequence that decrements. To achieve this, we use a for loop with decrementing indices. ... Using decrementing loops, the reverse traverse pattern would produce ...
🌐
Programiz
programiz.com › javascript › multidimensional-array
JavaScript Multidimensional Array
You can use the for...of loop to iterate over the multidimensional array. For example, let studentsData = [["Jack", 24], ["Sara", 23]]; for (let i of studentsData) { for (let j of i) { console.log(j); } } ... JavaScript for...
🌐
Dyn-web
dyn-web.com › javascript › arrays › multidimensional.php
Redirecting...
This tutorial describes and ... with JavaScript arrays. We cover: How to create an array, how to access and modify its elements, and other array basics. How to add elements to an array. How to remove elements from an array. How to iterate over the elements in an array. How to work with multidimensional ...
🌐
Codecademy
codecademy.com › forum_questions › 52579398abf82173e4001ffe
How to use foreach() for associative multidimensional arrays? | Codecademy
$myArray = array(array('color'=>'pink'), array('food'=>'dumplings'), array('sauce'=>'chilli') ); // On the line below, output one of the values to the page: //echo $myArray[1]['food']; // On the line below, loop through the array and output // *all* of the values to the page: foreach ($myArray as $cynaras) { foreach($cynaras as $items) { echo $cynaras." favorite ".$items."<br>"; } } Outputs: Array favorite pink Array favorite dumplings Array favorite chilli · How to use foreach for the associative and multidimensional array above?
🌐
freeCodeCamp
freecodecamp.org › news › nesting-for-loops-in-javascript
Nesting For Loops in JavaScript
June 2, 2020 - If you're having trouble understanding freeCodeCamp's Nesting For Loops challenge, don't worry. We got your back. In this problem you have to complete the multiplyAll() function, and takes a multi-dimensional array as an argument. Remember that ...
🌐
javaspring
javaspring.net › blog › for-loop-in-multidimensional-javascript-array
JavaScript Multidimensional Array: How to Iterate with For Loops vs Using Separate Arrays — javaspring.net
To work with data in a multidimensional ... The classic way to iterate over a 2D array is with nested for loops: an outer loop for rows and an inner loop for columns....