Contains Array prototypes and the function $A;
Valerio Proietti, http://mad4milk.net
MIT-style license.
Array.js | Contains Array prototypes and the function $A; |
Array | A collection of The Array Object prototype methods. |
Properties | |
each | Same as Array.each. |
copy | Copy the array and returns it. |
remove | Removes an item from the array. |
test | Tests an array for the presence of an item. |
extend | Extends an array with another |
associate | Creates an associative array based on the array of keywords passed in. |
Utility Functions | |
Functions | |
$A() | Same as Array.copy, but as function. |
A collection of The Array Object prototype methods.
Properties | |
each | Same as Array.each. |
copy | Copy the array and returns it. |
remove | Removes an item from the array. |
test | Tests an array for the presence of an item. |
extend | Extends an array with another |
associate | Creates an associative array based on the array of keywords passed in. |
Same as Array.each.
Copy the array and returns it.
an Array
var letters = ["a","b","c"];
var copy = ["a","b","c"].copy();
Removes an item from the array.
item | the item to remove |
the Array without the item removed.
["1","2","3"].remove("2") // ["1","3"];
Tests an array for the presence of an item.
item | the item to search for in the array. |
true | the item was found |
false | it wasn’t |
["a","b","c"].test("a"); // true
["a","b","c"].test("d"); // false
Extends an array with another
newArray | the array to extend ours with |
var Animals = ['Cat', 'Dog', 'Coala'];
Animals.extend(['Lizard']);
//Animals is now: ['Cat', 'Dog', 'Coala', 'Lizard'];
Creates an associative array based on the array of keywords passed in.
keys | the array of keywords. |
(sart code) var Animals = [‘Cat’, ‘Dog’, ‘Coala’, ‘Lizard’]; var Speech = [‘Miao’, ‘Bau’, ‘Fruuu’, ‘Mute’]; var Speeches = Animals.associate(speech); //Speeches[‘Miao’] is now Cat. //Speeches[‘Bau’] is now Dog. //... (end)
Functions | |
$A() | Same as Array.copy, but as function. |
function $A( array )
Same as Array.copy, but as function. Useful to apply Array prototypes to iterable objects, as a collection of DOM elements or the arguments object.
function myFunction(){
$A(arguments).each(argument, function(){
alert(argument);
});
};
//the above will alert all the arguments passed to the function myFunction.
function $A( array )