Tuesday , 18 June 2019
Home / Programming / JavaScript / Multidimensional Arrays – JavaScript Tutorial
Multidimensional Arrays
Multidimensional Arrays

Multidimensional Arrays – JavaScript Tutorial

This tutorial is part of the JavaScript tutorial series for beginners. To view the whole list of tutorials available and the order in which you should follow them, then click here.

When you hear the word multidimensional you think of space and time. In programming, it’s far more simpler than that. Multidimensional arrays are just arrays within arrays. Yes, it’s possible! Don’t worry, this tutorial doesn’t have any surprised ;).

Let’s clear your script and add this bit of code into it.

I create a variable named people and insert some regular values. Don’t worry about the formatting. You don’t have to put every value on a new line, but I do this to make it more readable.

The last value is an array.To create an array inside an array, you would do it just like any other array. You can input as many values as you want inside this array. You can even continue on with your array after your finished with the inner array.

Now, add this bit of code after your array.

This will simply output all values in the array. Since you’re not defining to access a certain element, it’ll assume you want all the values. It’ll work whether or not you’re using multidimensional arrays.

So, you may be wondering, what’s the difference between this and the join() method? Well, the join() method allows you to define a separator instead of using commas. Other than that, they do the same thing.

So, how do you access values that are inside an array? Simple, add this line of code.

First, you specify the index that contains the array, then you type in another square brackets. The second pair of brackets will represent the 2nd array. The index will restart at 0. So, the index 1, will be the value Karen.

You can even create an array inside your array inside your array. You would have a 3 dimensional array. The more in depth you go, then the more complicated it can get. It’s very rare to have a 3 dimension array. A 2 dimension array is usually as far as you’ll go.


Multidimensional arrays are used from time to time. They allow you to organize data more efficiently. There are other ways to do so, which we’ll learn in future tutorials.

About Jasko Koyn

Check Also


Audio – Advanced JavaScript Tutorial

The video and audio objects both have the same events, properties and methods. So, you …

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.