Here, we shall create the array in fig1.1 using the constructor function. As I said above, the array is an object. We simply use object features that will make the object behave like an array. This is it; the explanation is given below.
The name of the object type is CustomArray. Only properties are found in this particular object type; no methods have been included. The variable for the first property is "this." Note that the property has been defined by an index. We must always refer to it by an index. Note that the other properties have also been defined in this way. An object initializer is assigned to each of these properties (variables).
These object initializers are of different lengths. Each property in an object initializer is defined by an index. When you define a property by an index, you have to refer to it by an index. The rows of our array are the properties of the array object; the "this" keyword is used for that. The cells (columns) are properties of the object initializers. Now that the rows and cells have been defined by indices, we can use the double pair of square brackets [i][j] to address a cell.
For simplicity, all of the cell contents in this series will be strings.
After the constructor function in the code, an array (object) is created from the CustomArray object type. The name of this inherited array (created) is myArray.
There is an HTML button. The onclick attribute of this button has an alert statement. The value of the alert statement is
This is an expression. It returns the value of the cell in row 2 and column 3. Just bear in mind that not all rows may have cell (column) 3 in your projects because the rows can be of different lengths. In that case the expression will return as being undefined. In general, whenever you ask for the value of a cell whose row or column does not exist, you receive the information that it is undefined.
When the button in our code here is clicked, the alert box displays "val23," which is the value in row 2, column 3. Note the use of the double pair of square brackets in the value of the onclick attribute. In this series, the row number comes first, before the column (cell) number.