Home arrow JavaScript arrow Page 2 - A Custom 2D JavaScript Array
JAVASCRIPT

A Custom 2D JavaScript Array


If you do not like the normal way of creating a two-dimensional array, for any particular reason, then this article is for you. Let me emphasize here that there's already a strong and growing need to make web pages active. So you need to start thinking about writing a custom two-dimensional JavaScript array. You will see how easy it is to do this.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 06, 2009
TABLE OF CONTENTS:
  1. · A Custom 2D JavaScript Array
  2. · The Array Properties and Methods
  3. · Object Type Array with its Contents
  4. · Object Type Array Without Contents
  5. · The Constructor Function with a Number of Rows and Columns

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
A Custom 2D JavaScript Array - The Array Properties and Methods
(Page 2 of 5 )

I will make the design simple. The aim of this series is to show you how you can create your own custom array and not to show you how to create a supper array.

We shall see how to define the following properties and methods: 

Properties

height: Number of rows in the array.

Methods

insertRow: to insert a row in the array.

deleteRow: to delete a row.

I will show you how to add more properties and methods at the end of this two-part series.

Roots

Before we dive in, let me go over some facts about objects in JavaScript. First, an array is an ordered set of values associated with a single variable name. Objects and arrays in JavaScript are intimately related; in fact, they are different interfaces to the same data structure.

Second, you can use object initializers to create objects.

Finally, in JavaScript 1.0, you can refer to an object's properties by their property name or by their ordinal index. In JavaScript 1.1 or later, however, if you initially define a property by its name, you must always refer to it by its name, and if you initially define a property by an index, you must always refer to it by its index.

So, our two-dimensional array will be an object where we shall emphasize its array characteristics.

Object Initializer

You can create objects using an object initializer. Using object initializers is sometimes referred to as creating objects with literal notation.

The syntax for creating an object using an object initializer is:

objectName = {property1:value1, property2:value2,..., propertyN:valueN}

where objectName is the name of the new object, each property I is an identifier (either a name, a number, or a string literal), and each value I is an expression whose value is assigned to the property I. The objectName and assignment is optional. If you do not need to refer to this object elsewhere, you do not need to assign it to a variable.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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