JavaScript
  Home arrow JavaScript arrow Page 4 - An in depth discussion of JavaScript Array...
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

An in depth discussion of JavaScript Arrays
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 9
    2006-02-28

    Table of Contents:
  • An in depth discussion of JavaScript Arrays
  • Working with single dimensional arrays: discussion
  • Working with two dimensional arrays
  • Working with two dimensional arrays: discussion
  • Another way to work with two dimensional arrays

  • 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


    An in depth discussion of JavaScript Arrays - Working with two dimensional arrays: discussion


    (Page 4 of 5 )

    Within the code in the previous section, I mainly created a simple button (which is identified as “ButtonShow”).  The button is defined with an “onclick” event which calls a JavaScript function “ButtonShow_onclick”, which is defined as follows:

    function ButtonShow_onclick() {
    Show();
    } 

    The above function simply calls another JavaScript function named “Show.”  The function “Show” is defined as follows:

    function Show()
    {
          var ITArray = new Array(2300, 3105, 2909, 4800);
          var ProductionArray = new Array(1800, 1940, 2470, 4350);
          var ResearchArray = new Array(900, 1200, 1923, 3810);
          var salaryArray = new Array(ITArray, ProductionArray, ResearchArray);

          for (var i = 0; i < salaryArray.length; i++) {
                for (var j = 0; j < salaryArray[i].length; j++) {
                      document.write(salaryArray[i][j] + "\t");
                }
                document.write("<br>")
          }
    }

    Before starting this discussion, we need to understand what we are creating (in memory) from the above code.  Let me provide you a logical view for the array (“salaryArray”) in the above code. Consider the following figure (Fig 01):

    Just consider the above figure as a small part of memory identified by “salaryArray.”  All the black numbers correspond to values.  All the reds are access notations (the positions) for the values given in black.  Every access notation is a combination of a row index (in blue) and a column index (in green).

    We are trying to create three single dimensional arrays as part of the main array, and thus we describe the main array as a “two dimensional” array (which is very similar to the concept of matrices in mathematics). 

    According to the above code, the three single dimensional arrays (or rows) are “ITArray”, “ProductionArray” and “ResearchArray.  All of them have their own values (but the number of values in all of them is generally the same).  We created a main array named “salaryArray” which contains the three arrays in the form of a list (thus forming a table type of view).

    Finally, we retrieve and display all the values in the “salaryArray” with the following nested loop:

          for (var i = 0; i < salaryArray.length; i++) {
                for (var j = 0; j < salaryArray[i].length; j++) {
                      document.write(salaryArray[i][j] + "\t");
                }
                document.write("<br>")
          }

    With the above code fragment, the variable “i” corresponds to the “row index” and the variable “j” corresponds to the “column index.”

    More JavaScript Articles
    More By Jagadish Chaterjee


       · I think "An In Depth Look" is a bit of a misnomer. This is more of an Introduction...
       · May be you are right. I should have given a better title. thanks for the...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT