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.
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:
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.