The principle of multiple arrays provides for a single data object that contains a complete grid of data. Most common are 2 dimensional arrays. These arrays are best described as a table. They have a width and a height. Javascript does not natively support arrays beyond a single dimension and alternative methods are needed to be devised. I came across an instance where I would absolutely need to have a traditional symetrical 2 dimensional array. I tried many solutions but in the end I decided to devise my own solution. I created this object to be able to bring generic support for arrays beyond the first dimension. I have provided 2 methods which supply my object with the ability to fill its entire contents with a specified value or a random character.
This is restricted to displaying a 2D array with the object since any deeper would require a vastly complicated rendering system. If you want to see how this object handles 3 or 4 dimensional arrays I recommend snaging the source and trying it out for yourself.
MyArray = new ArrayDimension(X, Y...); |
Constructor |
MyArray.Fill(Value); |
Fills the entire object with a specific string. *This code can be removed if this feature is not needed. |
MyArray.FillRandom(); |
Fills the entire object with random content. *This code can be updated to handle different content. *This code can be removed if this feature is not needed. |
MyArray.Get(X, Y...); |
Specific Location Fetch. Just as you would request a specific location in an array. Pass the desired location of the value you wish to get. As with Inherent javascript
behavior you can fetch the object at a specific location as well. IE: passing 2 of 3 dimensions will get the object of that sits in the third dimension. |
MyArray.toString(true); |
Tride and True method component. Used to print out the Objects content. Passing the true value will make it print out a set of divs for the data to be formated in HTML. Otherwise you will get a pure string with endlines printed in it. |