We have a constructor function that has two parameters. The first one receives the number of rows; the second one receives the number of columns. Statements in the constructor functions create the rows (this[i]) and the cells (columns). Here we have a regular array with rows of the same length. The following code illustrates this:
The constructor function is CustomArray(y,x). The y parameter takes the arguments for the number of rows. The x parameter takes the argument for the number of columns (cells). The first code segment of this function forms the string for the object initializer for the rows. This is the same for all rows here. The code segment uses a for-loop for this. If there are five cells, each of them will be initially undefined.
The last code segment in the script forms the myArray array object of 6 rows and 5 columns. 6 and 5 are arguments of the constructor function. This code segment gives the value "val23" to the cell content of the cell at row 2, column 3.
You have two HTML buttons. When clicked, the first one displays the content of the cell at row 4, column 1. This is undefined. The second one, on the other hand, will display the value "val23," which is the content of the cell at row 2, column 3.
Let us take a break here. In the next part we shall look at the properties and methods.
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.