Home arrow JavaScript arrow Page 2 - Defining JavaScript Arrays Using Literal Notation

Defining JavaScript Arrays Using Literal Notation

In this article, George introduces us to the process of creating arrays in JavaScript using literal notation. Is it really that simple? George attemps to show us how easy it really is.

Author Info:
By: JavaScript Kit
Rating: 4 stars4 stars4 stars4 stars4 stars / 18
September 22, 2003
  1. · Defining JavaScript Arrays Using Literal Notation
  2. · Putting It to the Test

print this article

Defining JavaScript Arrays Using Literal Notation - Putting It to the Test
(Page 2 of 2 )

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[0][1] //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:

  1. JavaScript Graph It
  2. NosTree

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.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials