-3

How Do we use Three Dimensional Array in Javascript?

Please show a basic example.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Mayank Bothra
  • 93
  • 1
  • 1
  • 8
  • 4
    I believe you haven't tried or searched anything. – Manwal Jul 17 '14 at 07:54
  • possible duplicate of [Is it possible to create an empty multidimensional array in javascript/jquery?](http://stackoverflow.com/questions/7521796/is-it-possible-to-create-an-empty-multidimensional-array-in-javascript-jquery) – Theolodis Jul 17 '14 at 07:56
  • yes i did but couldnt understand the concept that what is the use of this when we can do with normal array – Mayank Bothra Jul 17 '14 at 07:57
  • Use of 3 dimensional is to store values like data of **3*3 rubic cube** – Manwal Jul 17 '14 at 07:58

1 Answers1

6

Multi dimensional array can be created like we create Single dimensional array in Javascript.

Creating Multi Dimensional array can be done by following:

var myArr = new Array();
myArr[0] = new Array();
myArr[0][0] = new Array()
myArr[0][0][0] = "test";
myArr[0][0][1] = "testnew";

alert(myArr[0][0][1]); 

There is also another way to do it, to create 3 Dimensional array without assigning values:

var myArr = new Array(new Array(new Array()));
Manwal
  • 23,450
  • 12
  • 63
  • 93