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 / 7
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

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

- 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 
Support 

Developer Shed Affiliates

 




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