Practically? Yes. You can create an array of arrays which functions as an 2D array as every item is an array itself:
let items = [
[1, 2],
[3, 4],
[5, 6]
];
console.log(items[0][0]); // 1
console.log(items[0][1]); // 2
console.log(items[1][0]); // 3
console.log(items[1][1]); // 4
console.log(items);
Run code snippetEdit code snippet Hide Results Copy to answer Expand
But technically this is just an array of arrays and not a “true” 2D array, as I. J. Kennedy pointed out.
It should be noted that you could keep nesting arrays into one another and so create “multidimensional” arrays.
Answer from Ballsacian1 on Stack Overflow Top answer 1 of 16
1428
Practically? Yes. You can create an array of arrays which functions as an 2D array as every item is an array itself:
let items = [
[1, 2],
[3, 4],
[5, 6]
];
console.log(items[0][0]); // 1
console.log(items[0][1]); // 2
console.log(items[1][0]); // 3
console.log(items[1][1]); // 4
console.log(items);
Run code snippetEdit code snippet Hide Results Copy to answer Expand
But technically this is just an array of arrays and not a “true” 2D array, as I. J. Kennedy pointed out.
It should be noted that you could keep nesting arrays into one another and so create “multidimensional” arrays.
2 of 16
515
You simply make each item within the array an array.
var x = new Array(10);
for (var i = 0; i < x.length; i++) {
x[i] = new Array(3);
}
console.log(x);
Run code snippetEdit code snippet Hide Results Copy to answer Expand
Creating 2D array in javascript
Hi All, I have a below code in which I am trying to fill the data from table that has few rows and columns. The problem is that I am unable to get the right value at indexes outside the loop. I need to add values at each row of the array and return the array to use in other functions. More on forum.freecodecamp.org
How to create an array of arrays using a loop
have you tried reading the mdn docs on your array constructor? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array you'e creating a new array, but you're putting the temp_array into a new array. You're not creating a new version of temp_array. this is what it should look like; const array_of_arrays = []; const loopOne = 5;//where loopOne is the random amount of times array_of_arrays is meant to loop? const loopTwo = 3;//the random length of the loop for the temp_array for( let i = 0; i < loopOne; i++ ){ let temp_array = []; for( let j = 0; j < loopTwo; j++ ){ temp_array.push(j); } array_of_arrays.push(temp_array); } console.log(array_of_arrays); More on reddit.com
An array of arrays of arrays?
Absolutely. You can create multiple arrays and then store each of those collections into a new array. You could continue doing that, but it'd probably get messy, code wise, and potentially detrimental to performance if your data was structured that way. More on reddit.com
Whats the difference between a multidimensional array in Javascript and a true multidimensional array?
With "true" multidimensional arrays, the dimension sizes are enforced (and typically fixed). With a JS multidimensional array, as you have laid out, if you change the size of e.g. b[0], the sizes of the other arrays do not change. The result is a jagged array. This SO question is more in-depth, though it talks about C# and not JavaScript: Why we have both jagged array and multidimentional array More on reddit.com
09:52
Multi-Dimensional Arrays - Javascript Programming 12 - YouTube
14:26
How to Work With Arrays in JavaScript (2025) - YouTube
06:31
Learn 2D ARRAYS in JavaScript in 6 minutes! ⬜ - YouTube
08:06
Learn JavaScript ARRAYS in 8 minutes! 🗃 - YouTube
JavaScript Basics Part 6: Arrays and Objects - Dive Into Data ...
10:01
JavaScript ARRAYS of OBJECTS are easy!
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
July 28, 2026 - The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name, and has members for performing common array operations. In JavaScript, arrays aren't primitives but are instead Array objects with the following core ...
Sentry
sentry.io › sentry answers › javascript › how can i create a two-dimensional array in javascript?
How can I create a two-dimensional array in JavaScript? | Sentry
February 15, 2023 - The Array() constructor can be called with or without the new keyword. Both constructions create an array instance. Youtube How Sentry.io saved me from disaster (opens in a new tab) Resources Improve Web Browser Performance - Find the JavaScript code causing slowdowns (opens in a new tab)
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › flat
Array.prototype.flat() - JavaScript | MDN
The flat() method of Array instances creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
freeCodeCamp
freecodecamp.org › news › javascript-2d-arrays
JavaScript 2D Array – Two Dimensional Arrays in JS
November 7, 2024 - You make a similar change on all elements by looping through, even though 2D arrays in JavaScript are not strict. There are two options for creating a multi-dimensional array. You can create the array manually with the array literal notation, which uses square brackets [] to wrap a list of elements separated by commas.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › concat
Array.prototype.concat() - JavaScript | MDN
The concat method does not recurse into nested array arguments. The concat() method is a copying method. It does not alter this or any of the arrays provided as arguments but instead returns a shallow copy that contains the same elements as the ones from the original arrays.
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
To construct a multidimensional array in JavaScript, we use arrays of arrays.
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-add-array-to-array-of-array
JavaScript - Add Array to Array of Array - GeeksforGeeks
July 23, 2025 - Here are the different methods to Array to an Array of Array (Multidimensional Array) in JavaScript · The push() method is one of the most common ways to add an array to an array of arrays. It adds a new element (in this case, an array) to the end of the array.
freeCodeCamp
forum.freecodecamp.org › curriculum help
Creating 2D array in javascript - Curriculum Help - The freeCodeCamp Forum
January 9, 2023 - Hi All, I have a below code in which I am trying to fill the data from table that has few rows and columns. The problem is that I am unable to get the right value at indexes outside the loop. I need to add values at each row of the array and return the array to use in other functions.
Code Institute
codeinstitute.net › blog › javascript › javascript arrays
Javascript Arrays: A Guide - Code Institute DE
December 20, 2022 - Since JavaScript arrays do not refer to associative arrays, it is impossible to access array items using random strings as indexes; instead, nonnegative numbers (or their corresponding string forms) must be used. Square brackets are used to indicate how to obtain an array’s elements. The array’s elements are each given an index. An array’s first index is always zero by default. The index value is enclosed in a set of square brackets, as in veggies [0], to retrieve a specific element from an array.
LinkedIn
linkedin.com › pulse › multidimensional-arrays-javascript-techniques-efficient-srikanth-r-szm1c
Multidimensional Arrays in JavaScript: Techniques for ...
Login to LinkedIn to keep in touch with people you know, share ideas, and build your career.
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
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › from
Array.from() - JavaScript | MDN
An iterable or array-like object to convert to an array. ... A function to call on every element of the array. If provided, every value to be added to the array is first passed through this function, and mapFn's return value is added to the array instead.
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Arrays
Arrays - Learn web development | MDN
Note: We've said it before, but just as a reminder — JavaScript starts indexing arrays at zero! Note that an array inside an array is called a multidimensional array. You can access an item inside an array that is itself inside another array by chaining two sets of square brackets together.