The thing about defining multi-dimensional arrays using the standard syntax is that we are often the ones taken into the next dimension before the process is over. Or is it just me? At any rate, literal notation simplifies things for everyone, as it supports nesting of other literal notation. This makes defining multi-dimensional arrays extremely easy and intuitive. The following example uses literal notation to define an array with 3 elements, the 1st element being a 2 dimensional array:
var myarray=[["New York", "LA", "Seattle"], China, Japan]
Yes, it's that easy. By merely using another literal notation as one of the array values, we add a 2nd dimension to that particular element. Let's go to "LA" shall we:
myarray //returns "LA"
Just to demonstrate literal notations' versatility in this respect, here's an array with its 1st element in turn being a 3 dimensional array:
var myarray=[[[2,4,6]], China, Japan]
Just remember, the more brackets you use, the deeper the hole you dig! To conclude this tutorial, here are two example scripts that use literal notation to greatly compact the code otherwise required using conventional array:
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.