JS-ARRAY-EXAMPLES
The following contains some sample usage of arrays:
var ar = new Array( 'cat', 'dog', 'horse' ); ar.slice( 1 ); // returns new [ 'dog', 'horse' ] array ar.push( 'fish' ); // ar is now [ 'cat', 'dog', 'horse', 'fish' ] ar.shift(); // returns 'cat', ar is now [ 'dog', 'horse', 'fish' ] ar.unshift( 'mouse' ); // ar is now [ 'mouse', 'dog', 'horse', 'fish' ] ar.pop(); // returns 'fish', ar is now [ 'mouse', 'dog', 'horse' ] ar.sort(); // ar is now [ 'dog', 'horse', 'mouse' ] ar.reverse(); // ar is now [ 'mouse', 'horse', 'dog' ] ar[4] = 'boat'; // ar is now [ 'mouse', 'horse', null, null, 'boat' ] delete ar[0]; // ar is now [ null, 'horse', null, null, 'boat' ] ar.compact(); // ar is now [ 'horse', 'boat' ] ar.has( 'horse' ); // returns true ar.has( 'all', 'horse', 'bee' ); // returns false ar.has( 'any', 'dog', 'bee', 'boat' ); // returns true ar.union( 'bee', 'horse' ); // ar is now [ 'horse', 'boat', 'bee' ] ar.subtract( 'boat', 'horse' ); // ar is now [ 'bee' ] ar.shift( 'dog' ); // ar is now [ 'dog', 'bee' ] ar.push( 'dog', 'bee' ); // ar is now [ 'dog', 'bee', 'dog', 'bee' ] ar.unique(); // ar is now [ 'dog', 'bee' ]; ar.random(); // returns either 'dog' or 'bee' randomly ar.length = 1; // ar is [ 'dog' ]; ar.length = 0; // ar is now empty