Friday , 19 October 2018
Home / Programming / JavaScript / Multidimensional Arrays – JavaScript Tutorial
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.

## Conclusion

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.

## Audio – Advanced JavaScript Tutorial

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

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

ULTIMATE NODE JS WITH SQL COURSE
Want to learn how to create web applications with Node.js and SQL? Check out my course!
Get 93% off my course. You'll also learn how to build real world applications using Node and SQL. This is a limited time offer
Yes, I would like to get 93% off your course!
No Thanks!