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/

Answer from Jared Farrish on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-multidimensional-array
JavaScript Multidimensional Array - GeeksforGeeks
A multidimensional array in JavaScript is an array that contains other arrays as its elements.
Published: July 12, 2025
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
People also ask

How do you declare a multidimensional array in JavaScript?
You declare a multidimensional array in JavaScript as an array of arrays. For example, a 2D array can be declared like this: `let multiArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];`.
🌐
vaia.com
vaia.com › javascript multidimensional arrays
Javascript Multidimensional Arrays: Examples | Vaia
How do you initialize a multidimensional array with values in JavaScript?
You can initialize a multidimensional array with values in JavaScript by using nested arrays, for example: `let multiArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];`. Each inner array represents a row in the multidimensional array.
🌐
vaia.com
vaia.com › javascript multidimensional arrays
Javascript Multidimensional Arrays: Examples | Vaia
How do you iterate through a multidimensional array in JavaScript?
You can iterate through a multidimensional array in JavaScript using nested `for` loops. Each `for` loop targets a specific dimension of the array. For example, the outer loop iterates through the primary array, and the inner loop iterates through each sub-array. This allows you to access individual elements.
🌐
vaia.com
vaia.com › javascript multidimensional arrays
Javascript Multidimensional Arrays: Examples | Vaia
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › javascript multidimensional array
JavaScript Multidimensional Array
November 8, 2024 - However, you can create one by defining an array where each element itself is an array. So, a JavaScript multidimensional array is essentially an array of arrays.
🌐
Programiz
programiz.com › javascript › multidimensional-array
JavaScript Multidimensional Array
In JavaScript, multidimensional arrays contain another array inside them.
🌐
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
In a 1-dimensional array, the [n] notation is used to access the (n+1)th element. For example, in the array ['a', 'b', 'c'], to access the element 'b', you would use array[1] since indices are zero-based. For multidimensional arrays, each element is itself an array.
🌐
Vaia
vaia.com › javascript multidimensional arrays
Javascript Multidimensional Arrays: Examples | Vaia
Remember, JavaScript arrays are flexible, meaning you can dynamically change their size and add new elements as needed. Accessing data within a multidimensional array involves using multiple indices. You must specify the index of the sub-array first and then the index of the element you want to access.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › what is a multidimensional array in javascript?
Multidimensional Array in JavaScript - Scaler Topics
July 14, 2024 - A multidimensional array in javascript is an array that has one or more nested arrays.
🌐
JavaScript in Plain English
javascript.plainenglish.io › chapter-58-mastering-multidimensional-arrays-in-javascript-a-deep-dive-e21f1281448d
Chapter 58:Mastering Multidimensional Arrays in JavaScript: A Deep Dive | by Aryan kumar | JavaScript in Plain English
October 18, 2024 - In other words, a multidimensional array is like an Excel sheet, where rows and columns of data are stored in a structured way. In JavaScript, arrays are flexible in how they can be declared.
🌐
Zenva
gamedevacademy.org › home › web development › frontend development › a useful introduction to javascript multidimensional arrays
A Useful Introduction To JavaScript Multidimensional Arrays - GameDev Academy
Multidimensional JavaScript Arrays are basically JavaScript Arrays of arrays . For example: let mArr = [[1,2,3],[4,5,6,7]]. This allows for an intuitive way to store 2D, 3D, or even higher dimensional values.
Published: October 21, 2023
🌐
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.
🌐
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.
🌐
Dustin John Pfister
dustinpfister.github.io › 2020 › 03 › 31 › js-array-multidimensional
Multidimensional arrays in javaScript | Dustin John Pfister at github pages
November 21, 2021 - The most common way of making a multidimensional array in javaScript might be to just have arrays of arrays, or in other words just nesting arrays as elements for arrays. That is having a single array, and then have each element in that array ...
🌐
Medium
medium.com › javascript-in-plain-english › javascript-multi-dimensional-arrays-7186e8edd03
JavaScript Multi-Dimensional Arrays | by gravity well (Rob Tomlin) | JavaScript in Plain English
September 18, 2021 - JavaScript Multi-Dimensional Arrays The Truth Comes Out The truth is, JavaScript does not directly support two or multi-dimensional arrays. Some languages, C#, Java and even Visual Basic, to name a …
🌐
TutorialsPoint
tutorialspoint.com › article › multi-dimensional-arrays-in-javascript
Multi Dimensional Arrays in Javascript
March 15, 2026 - 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.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › multi-dimensional array in javascript
Multi-Dimensional Array in JavaScript | Properties & Top 8 Methods Used
March 17, 2023 - Multidimensional arrays in JavaScript provides the facility to store different types of data into a single array with each element inner array capable of storing independent data from the rest of the array with its length, which cannot be achieved ...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
JavaScripter
javascripter.net › faq › twodimensional.htm
JavaScript: Multidimensional Arrays
Multidimensional Arrays in JavaScript JavaScript FAQ | JavaScript Arrays FAQ · Question: How do I create a two-dimensional array in JavaScript
🌐
LogRocket
blog.logrocket.com › home › 5 best javascript multidimensional array libraries
5 best JavaScript multidimensional array libraries - LogRocket Blog
June 4, 2024 - Learn more about the 5 best JavaScript libraries for dealing with multidimensional arrays, such as ndarray, math.js, and NumJs.
🌐
WsCube Tech
wscubetech.com › resources › javascript › multidimensional-array
Multidimensional Array in JavaScript: With Examples
November 21, 2025 - Learn multidimensional arrays in JavaScript with simple explanations and examples. Understand how to create, access, modify, and more. Read now.