Home | Docs | Download

Classes


top

Prototypes: Array

Method Summary
Method Attributes Method Name and Description
 
push()
Adds push method to array if not present.
 
indexOf(object)
Returns the position of an array member.
 
inArray(value)
Checks if "value" is an array member.
 
filter(fnc)
Filters all array members on a function condition and returns the new array.
 
map(fnc)
Applies a function to each elements of the given array.
 
checkAgainst(value)
Checks if value is in array, if not adds value to array.
 
merge(array)

Merges two arrays filtering duplicates

requires Bicycle Chain

 
remove(from, to)

Removes elements from an array

requires Bicycle Chain

Method Detail
{Array} push()
Adds push method to array if not present.
Returns:
{Array} The new array length
See:
Prototype JavaScript framework, version 1.4.0

{Number} indexOf(object)
Returns the position of an array member.
		var myArray = ['apple', 'lemon', 'orange', 'banana'];
		alert(myArray.indexOf('orange'));
		// will alert 2
Parameters:
{Object} object
A variable to search for
Returns:
{Number} The position of array member or -1 if not found
See:
liberty - Basic JavaScript Library 0.1

{Bool} inArray(value)
Checks if "value" is an array member.

Author: EmbiMedia.
		var myArray = ['apple', 'lemon', 'orange', 'banana'];
		alert(myArray.inArray('apple')); // will alert "true"
Parameters:
{Object} value
The element to search inside the array
Returns:
{Bool} Returns true if "value" is an array member
See:
http://code.mikebrittain.com/2006/01/inarray-method-for-javascript-and-actionscript/

{Array} filter(fnc)
Filters all array members on a function condition and returns the new array.

Author: Svend Tofte.
		var myArray = [1,2,-2,3,-4,4,5];
		myArray.filter(function (n){
			return n>0;
		});
		//returns myArray = [1,2,3,4,5]
Parameters:
{Function} fnc
Function to filter array members
Returns:
{Array} The filtered array
See:
http://www.svendtofte.com/

map(fnc)
Applies a function to each elements of the given array.

Author: Svend Tofte.
		// create a string named "arrayString" listing element value and index number
		var myArray = ['apple', 'lemon', 'orange', 'banana'];
		var arrayString = "";
		myArray.map( function (el,i) {
			arrayString += el+i+", ";
		});
		alert(arrayString); // will alert "apple0, lemon1, orange2, banana3"
Parameters:
{Function} fnc
Function to iterate on each element may have two arguments: element and its array index.
See:
http://www.svendtofte.com/

{Array} checkAgainst(value)
Checks if value is in array, if not adds value to array.
		var my1stArray = ['apple', 'lemon'];
		var my2ndArray = ['lemon', 'orange', 'banana'];
		for (i=0;i<my2ndArray.length;i++) {
			my1stArray.checkAgainst(my2ndArray[i]);
		}
		// will return my1stArray = ['apple', 'lemon', 'orange', 'banana']
Parameters:
{Object} value
The element to insert in the array
Returns:
{Array} The new array

{Array} merge(array)
Merges two arrays filtering duplicates
var array1 = ["one","two","three"];
var array2 = ["three","four","five"];
array1.merge(array2);
// returns ["one","two","three","four","five"]
Parameters:
{Array} array
The array to merge with
Returns:
{Array} the merged array

{Number} remove(from, to)
Removes elements from an array

Author: John Resig (MIT Licensed).
// Remove the second item from the array
array.remove(1);
// Remove the second-to-last item from the array
array.remove(-2);
// Remove the second and third items from the array
array.remove(1,2);
// Remove the last and second-to-last items from the array
 array.remove(-2,-1);
Parameters:
{Number} from
Index of the element to remove. Positive or negative
{NUmber} to
How many elements to remove. Positive or negative
Returns:
{Number} Sliced array lengths

Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 12 2009 21:32:34 GMT+0100 (CET)