var arr1 = [ "I", "learn", "JavaScript", "and", "it's", "fun" ];
var arr2 = arr1.slice(2,3); // -> JavaScript (just 1 element returned)
arr2 = arr1.slice(2,5); // -> JavaScript, and, it's (3 elements)
alert( "Compare arrays:\n" + arr1 +"\n"+ arr2 );
Tip: Array.slice() and String.slice() are two different methods - one works with start and end array index as delimiters, the other with text and character position indices to extract substrings.
var arr1 = [ "I", "learn", "JavaScript" ];
var arr2 = arr1.slice(0);
alert( "Compare arrays:\n" + arr1 +"\n"+ arr2 );
var arr1 = [ "I", "learn", "JavaScript", "and", "it's", "fun" ];
var arr2 = arr1.slice(-3); // get last 3 elements of first array
alert( "One element per line:\n" + arr2.join("\n") );
Note: join() concatenates elements using a string you pass (new line character, in this case).
$arr1 = array( 'I', 'learn', 'PHP' );
$arr2 = array_slice( $arr1, 1, 2 );
print_r( $arr2 ); // Array ( [0] => learn [1] => PHP )
Sister method: splice() lets you extract, remove, or and replace elements from other arrays.