Member-only story
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 few, let one declare multi-dimensional arrays. But not JavaScript. In JavaScript you have to build them.
Personal note: I like having to build them. It helps me understand how they really work.
We will focus on two-dimensional Arrays.
Definition
A two-dimensional array is a collection of items that are organized as a matrix of rows and columns, and is given a name.
Abstract Solution
The two-dimensional array in JavaScript is an Array of Arrays, so we create an Array of one-dimensional Array objects.
Let’s examine this through a problem and a solution.
The Problem
Let’s say I want a two dimensional Array, called letters, of alphabetic letters, such as,
If we look closely we can see that the first row of letters is a one-dimensional Array, firstRow=[a,f,k]. The second row is a one-dimensional Array also, secRow=[b,g,l] and so on.