[turboid] javascript solutions

Home     Contact     Search     About me
05 Apr 2012

Better array functions for JavaScript

Easier manipulation of arrays

Whoever works a lot with arrays in different ways will after some time discover that standard JavaScript is a little bit poor in terms of array treating functions. This is why this article introduces you to the array functions provided by Turboid, which makes your life with arrays much easier.

Here is a nice collection of functions which allow you to drop and insert elements in an array where you want and by the criteria you want. Especially associative arrays are now much easier to handle. A special feature are the pointer functions which let you walk through an array without forgetting where you have been in it at your last made step.


Deletes an element at an array index of your choice. This is easier and more flexible than standard functions like .pop(), .shift() or .slice(). Returns the modificated array.


Deletes an element by value instead of deleting it by index. All elements containing value are affected. Returns the modificated array.

[Array].insertAt(i, val)

Inserts a new element at index i, containing the value "val".


Returns whether the array contains an element containing the passed value. Usage example: if(myList.contains("Herbert"))... Not for associative arrays.


Returns the index of the first element containing value.


Gets the average value of all numbers in the array.


Although associative arrays officially don't work with indexes, this function informs you about the value which is saved at the passed index, solely based on the chronological order which the values of the associative array have been saved with.


The same as .getValueAtPoint(index), providing the key name instead of the value.


Returns the number of elements in an associative array.


Returns the key of the highest value in an array or object


Returns the key of the lowest value in an array or object

valuesort(toBeSorted [, -1])

Sorts an array (value) by value. The optional argument -1 lets the array be sorted setting the highest value as first element and the lowest value as the last element.


Sorts an assoiciative array by its key names.


Checks if var is a real array already containing elements.


Lets you walk step by step through an array, returning the value of each next element, beginning with index 0. Each time the function is used, its pointer is set on the next index. Returns null after passing the last element.


Lets the pointer of .getNext() jump to next.


Like .getNext(), but always returning the next previous element.


Gets the current element without changing the pointer.


Checks if val is an array or not.


Prevents the standard JavaScript array function .sort() dividing words written in upper case and words written in lower case in two different groups. Usage: [Array].sort(ignoreUC)

In order to use these extra functions, simply download the free Turboid framework and put it into the directory of your HTML file, then write this line into the head section of your HTML file, and that's it:


Alternatively, you can use the smaller Turboid core along with Turboid varTools if you don't want to download the whole framework.


Add comment:

Name: (required)
E-Mail: (required, remains invisible)
Please check all (anti-spam):