Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Array() > Arrays Containing Other Arrays (Multidimensional Arrays)

Arrays Containing Other Arrays (Multidimensional Arrays)

Since an array can hold any valid JavaScript value, an array can contain other arrays. When this is done, the array containing encapsulated arrays is considered a multidimensional array. Accessing encapsulated arrays is done by bracket chaining. Below, we create an array literal that contains an array, inside of which we create another array literal, inside of which we create another array literal, containing a string value at the 0 index.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var myArray = [[[['4th dimension']]]];
console.log(myArray[0][0][0][0]); // logs '4th dimension'

</script></body></html>

The code above is rather silly, but you can take away the fact that arrays can contain other arrays and you can access encapsulated arrays indefinitely.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint