var multiArray = [ ['element 0, 0', 'element 0, 1', 'element 0, 2'], ['element 1, 0', 'element 1, 1']];

and so on...

EDIT every single notation in [] is an array, so you just have to combine them into an another array

Answer from haynar on Stack Overflow
🌐
Programiz
programiz.com › javascript › multidimensional-array
JavaScript Multidimensional Array
In JavaScript, a multidimensional array contains another array inside it. In this tutorial, you will learn about JavaScript multidimensional arrays with the help of examples.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-multidimensional-array
JavaScript Multidimensional Array - GeeksforGeeks
Check Array Lengths: Always check the array's length before accessing its elements to avoid errors and undefined values. JavaScript does not have built-in support for multidimensional arrays like some other programming languages, but you can ...
Published   July 12, 2025
🌐
W3docs
w3docs.com › javascript
How to Create a Two Dimensional Array in JavaScript
Multidimensional arrays are known in JavaScript as arrays inside another array as they are created by using another one-dimensional array.
🌐
Era-edta
web.era-edta.org › uploads › gme6y › multidimensional-array-in-javascript-w3schools
multidimensional array in javascript w3schools
For example: If we create an array ... or removing elements. syntax for javascript array. To define a multidimensional array its exactly the same as defining a normal one-dimensional array. 2d array javascript w3schools....
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › javascript multidimensional array
JavaScript Multidimensional Array
November 8, 2024 - This tutorial shows you how to effectively create JavaScript multidimensional arrays using an array of arrays.
🌐
W3Schools
w3schools.com › js › js_arrays.asp
JavaScript Arrays
An array can hold many values under a single name, and you can access the values by referring to an index number. Using an array literal is the easiest way to create a JavaScript Array.
🌐
Medium
medium.com › @rabailzaheer › mastering-nested-and-multidimensional-arrays-in-javascript-with-examples-best-practices-d27fa48d219f
Mastering Nested and Multidimensional Arrays in JavaScript (With Examples & Best Practices)
February 26, 2025 - Learn how to work with nested and multidimensional arrays in JavaScript! This guide covers creation, manipulation, iteration techniques, and best practices
Find elsewhere
🌐
Alma Better
almabetter.com › bytes › tutorials › javascript › multidimensional-array-in-javascript
Multidimensional Array in JavaScript
April 25, 2024 - A multidimensional array in JavaScript is an array of arrays. It is a type of array that allows developers to store data in a matrix-like structure, with multiple levels of arrays within arrays.
🌐
DEV Community
dev.to › who_tf_cares › how-to-work-with-multidimensional-arrays-in-javascript-9jl
How to Work with Multidimensional Arrays in JavaScript - DEV Community
January 14, 2025 - Essentially, a multidimensional array in JavaScript is an array within another array. To make an array behave like a multidimensional array, you can place arrays inside a parent array, effectively mimicking a multidimensional structure.
🌐
CodeSignal
codesignal.com › learn › courses › multidimensional-arrays-and-their-traversal-in-javascript › lessons › multidimensional-arrays-and-their-traversal-in-javascript
Multidimensional Arrays and Their Traversal in JavaScript
Welcome to today's session on "Multidimensional Arrays and Their Traversal in JavaScript". Multidimensional arrays are types of arrays that store arrays at each index instead of single elements. They allow us to create complex data structures that can model various real-life scenarios.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-2d-array
JavaScript 2D Array | GeeksforGeeks
December 28, 2024 - In JavaScript, there is no direct syntax for multidimensional arrays, but you can achieve this by creating arrays within arrays.Creating a
Top answer
1 of 15
337
var numeric = [
    ['input1','input2'],
    ['input3','input4']
];
numeric[0][0] == 'input1';
numeric[0][1] == 'input2';
numeric[1][0] == 'input3';
numeric[1][1] == 'input4';

var obj = {
    'row1' : {
        'key1' : 'input1',
        'key2' : 'input2'
    },
    'row2' : {
        'key3' : 'input3',
        'key4' : 'input4'
    }
};
obj.row1.key1 == 'input1';
obj.row1.key2 == 'input2';
obj.row2.key1 == 'input3';
obj.row2.key2 == 'input4';

var mixed = {
    'row1' : ['input1', 'inpu2'],
    'row2' : ['input3', 'input4']
};
mixed.row1[0] == 'input1';
mixed.row1[1] == 'input2';
mixed.row2[0] == 'input3';
mixed.row2[1] == 'input4';

http://jsfiddle.net/z4Un3/

And if you're wanting to store DOM elements:

var inputs = [
    [
        document.createElement('input'),
        document.createElement('input')
    ],
    [
        document.createElement('input'),
        document.createElement('input')
    ]
];
inputs[0][0].id = 'input1';
inputs[0][1].id = 'input2';
inputs[1][0].id = 'input3';
inputs[1][1].id = 'input4';

Not real sure how useful the above is until you attach the elements. The below may be more what you're looking for:

<input text="text" id="input5"/>
<input text="text" id="input6"/>
<input text="text" id="input7"/>
<input text="text" id="input8"/>    
var els = [
    [
        document.getElementById('input5'),
        document.getElementById('input6')
    ],
    [
        document.getElementById('input7'),
        document.getElementById('input8')
    ]
];    
els[0][0].id = 'input5';
els[0][1].id = 'input6';
els[1][0].id = 'input7';
els[1][1].id = 'input8';

http://jsfiddle.net/z4Un3/3/

Or, maybe this:

<input text="text" value="4" id="input5"/>
<input text="text" value="4" id="input6"/>
<br/>
<input text="text" value="2" id="input7"/>
<input text="text" value="4" id="input8"/>

var els = [
    [
        document.getElementById('input5'),
        document.getElementById('input6')
    ],
    [
        document.getElementById('input7'),
        document.getElementById('input8')
    ]
];

var result = [];

for (var i = 0; i < els.length; i++) {
    result[result.length] = els[0][i].value - els[1][i].value;
}

Which gives:

[2, 0]

In the console. If you want to output that to text, you can result.join(' ');, which would give you 2 0.

http://jsfiddle.net/z4Un3/6/

EDIT

And a working demonstration:

<input text="text" value="4" id="input5"/>
<input text="text" value="4" id="input6"/>
<br/>
<input text="text" value="2" id="input7"/>
<input text="text" value="4" id="input8"/>
<br/>
<input type="button" value="Add" onclick="add()"/>

// This would just go in a script block in the head
function add() {
    var els = [
        [
            document.getElementById('input5'),
            document.getElementById('input6')
        ],
        [
            document.getElementById('input7'),
            document.getElementById('input8')
        ]
    ];

    var result = [];

    for (var i = 0; i < els.length; i++) {
        result[result.length] = parseInt(els[0][i].value) - parseInt(els[1][i].value);
    }

    alert(result.join(' '));
}

http://jsfiddle.net/z4Un3/8/

2 of 15
31

Quote taken from Data Structures and Algorithms with JavaScript

The Good Parts (O’Reilly, p. 64). Crockford extends the JavaScript array object with a function that sets the number of rows and columns and sets each value to a value passed to the function. Here is his definition:

Array.matrix = function(numrows, numcols, initial) {
    var arr = [];
    for (var i = 0; i < numrows; ++i) {
        var columns = [];
        for (var j = 0; j < numcols; ++j) {
            columns[j] = initial;
        }
        arr[i] = columns;
    }
    return arr;
}

Here is some code to test the definition:

var nums = Array.matrix(5,5,0);
print(nums[1][1]); // displays 0
var names = Array.matrix(3,3,"");
names[1][2] = "Joe";
print(names[1][2]); // display "Joe"

We can also create a two-dimensional array and initialize it to a set of values in one line:

var grades = [[89, 77, 78],[76, 82, 81],[91, 94, 89]];
print(grades[2][2]); // displays 89
🌐
freeCodeCamp
freecodecamp.org › news › javascript-2d-arrays
JavaScript 2D Array – Two Dimensional Arrays in JS
November 7, 2024 - [ a1, a2, a3, ..., an, b1, b2, b3, ..., bn, c1, c2, c3, ..., cn, . . . z1, z2, z3, ..., zn ] In JavaScript, there is no direct syntax for creating 2D arrays as with other commonly used programming languages like C, C++, and Java.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-create-two-dimensional-array-in-javascript
How to Create Two Dimensional Array in JavaScript? - GeeksforGeeks
November 8, 2024 - Creating an array of partial objects from another array is a useful technique in JavaScript, especially for data transformation and manipulation. This guide covers various methods to efficiently create these arrays, enhancing your ability to ...
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › chapters › arrays › multi-dimensional-arrays.html
8.4. Multi-Dimensional Arrays — Introduction to Professional Web Development in JavaScript documentation
The row and column analogy is used to help visualize a two dimensional array, however it's not a perfect analogy. There are no specific JavaScript language rules forcing the inner arrays to all have the same length.
🌐
Code Highlights
code-hl.com › home › javascript › tutorials
Ultimate Guide to Multidimensional Array in JavaScript | Code Highlights
February 8, 2024 - This guide is your one-stop resource for understanding and implementing multidimensional arrays in JavaScript.
🌐
Team Treehouse
teamtreehouse.com › library › javascript-arrays › what-is-a-multidimensional-array
What is a Multidimensional Array? (How To) | JavaScript Arrays | Treehouse
Learn how to create and work with arrays that contain other arrays, or "multidimensional arrays".
Published   June 16, 2020
🌐
TutorialsPoint
tutorialspoint.com › article › multi-dimensional-arrays-in-javascript
Multi Dimensional Arrays in Javascript
3 weeks ago - Multi-dimensional arrays in JavaScript are arrays that contain other arrays as elements. They're useful when you need to organize data in rows and columns, like storing temperatures for each day of the week at different time intervals.