JavaScript
  Home arrow JavaScript arrow Page 4 - Properties and Methods of Custom 2D JavaSc...
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

Properties and Methods of Custom 2D JavaScript Arrays
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-10-14

    Table of Contents:
  • Properties and Methods of Custom 2D JavaScript Arrays
  • The Constructor Function
  • The Array Object Type Methods
  • Adding Cells

  • 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


    Properties and Methods of Custom 2D JavaScript Arrays - Adding Cells


    (Page 4 of 4 )

    After adding a row, the row is empty. You do not really need any function to add a cell. Rows are object initializers. By just assigning a value to any cell, you create (add) a cell with its value.

    Let us look at an example. Consider the CustomArray() array object type that we have created. Assume that you have created the myArray object from CustomArray(). Assume that the row you inserted is at index 2. Below the constructor function in the code, you can type,

    myArray[2][3] = “val23”;

    The row you have just inserted is blank and is at row index 2. This statement creates a cell at the position of cell index 3 in the row, and gives it the value “val23.”

    Note that you cannot add a cell like this to a row that does not exist or has not been inserted. If you want to add a cell to a row that is not in the array, first insert the row as shown above. Remember that the method of insertion shown above can be used to insert a row outside the range of rows that are already there.

    Assigning Values

    You can assign a value to any cell in any row that already exists in the array. If you want to assign a value to a cell in a row that does not exist, you have to insert that row first, and then you assign a value to any cell in the inserted row. When you assign a value to any cell in the inserted row, the cell is automatically created. If the cell was already there, the value (content) is replaced. A statement like the following will either create a new cell and its value in any row that exists, or have the value of the identified cell replaced:

    myArray[4][1] = “val23”;

    Having Other Properties and Methods

    You can give a property to the array object type, as we gave the height property. You can give a method as we gave the insertRow method. If you want, for example, a method to sort the data in a column, you need to know how to write a sort function first; then you type the function into the constructor function as we typed the insertRowFn(i) function above. You make this function a method by declaring a method, as we did for the insertRow method.

    Always remember that your 2D array object type is an object of object constructor function. So you give properties and methods as you would to any object.

    Follow the link below for the complete code.

    Custom 2D JavaScript Array.ZIP

    Thanks for reading this two-part series.


    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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek