Array Methods
join() converts an array into a string, using a given separator:
var a =[1,2,3];
a.join('==');
reverse()
var a=[1,2,3];
a.reverse();
sort()
var a=['beta','alpha','delta'];
a.sort();
var a=[1,2,3,4];
a.sort(function(x,y){return y-x;}); later...
concat(x) concatenate with x
var a=[1,2,3];
a.concat(4,5);
a.concat([4,5]);
a.concat([4,5],[6,7]);
a.concat(4,5,[6,[7,8]]); hmmm, try in firebug.
slice(start,length) returns a subset. Negative means start from end.
var a=[1,2,3,4,5];
a.slice(0,3);
a.slice(3);
a.slice(1,-1);
a.slice(-3,-1);
a.splice(start, length) modifies array deleting elements:
var a=[1,2,3,4,5,6,7,8];
a.splice(4);
var a=[1,2,3,4,5,6,7,8];
a.splice(1,2);
var a=[1,2,3,4,5,6,7,8];
a.splice(2,4);
a.push(x) adds x to the end and
pop() deletes and returns the last element.
a.unshift(x) and shift() are the same but from the beginning.
José M. Vidal
.
38 of 65