How to create multidimensional array with JavaScript?

Sometimes, we want to create multidimensional array with JavaScript.

In this article, we’ll look at how to create multidimensional array with JavaScript.

How to create multidimensional array with JavaScript?

To create multidimensional array with JavaScript, we can assign the values to the position with the given indexes.

For instance, we write

const numeric = [
  ["input1", "input2"],
  ["input3", "input4"],
];
numeric[0][0] == "input1";
numeric[0][1] == "input2";
numeric[1][0] == "input3";
numeric[1][1] == "input4";

by putting arrays into arrays like

const numeric = [
  ["input1", "input2"],
  ["input3", "input4"],
];

We also assign values to the positions we want with

numeric[0][0] == "input1";
numeric[0][1] == "input2";
numeric[1][0] == "input3";
numeric[1][1] == "input4";

where the first index is the position of the outer array and the 2nd is the position of the inner array.

Conclusion

To create multidimensional array with JavaScript, we can assign the values to the position with the given indexes.