JavaScript
  Home arrow JavaScript arrow Page 2 - Defining JavaScript Arrays Using Literal N...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Defining JavaScript Arrays Using Literal Notation
By: JavaScript Kit
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2003-09-22

    Table of Contents:
  • Defining JavaScript Arrays Using Literal Notation
  • Putting It to the Test

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

     

    JAVASCRIPT ARTICLES

    - Using jQuery to Preload Images with CSS and ...
    - Using Client-Side Scripting to Preload Image...
    - Removing Non-Semantic Markup when Preloading...
    - Using the Display CSS Property to Preload Im...
    - Preloading Images with CSS and JavaScript
    - Scaling and Moving Web Page Elements with th...
    - Fading, Hiding and Sliding HTML Elements wit...
    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek