MDArrayEngine: Javascript Array Class
mdArrayEngine: A free to use Javascript class for multi dimension array creation and manipulation
The MDArrayEngine class provides several functions to create and manipulate multi-dimensional arrays like adding, update, retrieve and delete scalar or array elements, searching for values, sum the element values and display the array values in a HTML page, it should assist you with any Javascript projects incorporating multi dimensional array use.
As MDArrayEngine is a dual MIT & GPL license, please feel free to modify or extend the class. If you feel that others could benefit from your work, please include a message here and your additions to the base class will be included as appropriate.
How to Instantiate:
1. Include the file mdArrayEngine.js in your project.
1 | <script type="text/javascript" src="js/mdArrayEngine.js"></script> |
2. in your javascript, instantiate the array class in the following manner:
2 3 4 5 6 7 8 9 10 11 12 13 | <script type="text/javascript"> // instantiate the object var a = KROMOSOME.MDArrayEngine; // initialise the object a.init(); // load the array with values a.pushValue(['test','try','alerts']); // get all array values as a formatted HTML table var html = a.arrayDump(); // output table to document to check values document.write(html); </script> |
List of KROMOSOME.MDArrayEngine functions:
- init(): Initialize the class array.
- getLength(): Return the length of the array.
- getRowLength([int] row): Return the length of the array’s row.
- pushValue([object] v): Push string or array of values onto the end of the array.
- rowPush([string] searchValue, [object] addValues): Add items to an existing row where the searchValue matches.
- indexOfValue([object] v): Return the array indices of the value (string or array) in the array.
- getValue([int] iRow, [int] iCol): Return a value from the array matching the supplied row and column numbers.
- setValue([int] iRow, [int] iCol, [object] data): Assign a value to the array matching the supplied row and column numbers.
- getRow([int] iRow): Return a row from the array matching the supplied row number.
- getAllValues(): Return the entire contents of the array as an array.
- updateItem([object] searchVal, [object] replaceVal): Replace the first occurrence of searchVal with replaceVal.
- upadteRow([object] searchVal, [object] replaceVal): Replace a row in the array on the first match of searchVal.
- deleteRow([int] row): Delete the row number corresponding to the row variable.
- updateRow_DualCondition([string] condition1, [string] condition1, [object] updateData): Updates differences in matching row with data from updateData, or inserts a new row if no match found on search condition1 & condition2, returns true for success, false for failure.
- column_Arithmetic_Sum_SingleCondition([int] conditionalColumn, [object] value, [int] columnToAdd): Sum the values of the columnToAdd WHERE conditionalColumn = x AND conditionalColumn value = y.
- getJSON(): return the multi dimensional array as a JSON data type.
- arrayDump(): Display the entire contents of the array as an html table.

