// Declare array of length 6:
var arr = [ "I", "learn", "JavaScript", "and", "it's", "fun" ];
var del = arr.splice( 2, 1 ); // Delete 1 element at index 2
// Show delete item and the modified array:
alert( "Element deleted = " + del + "\n" + arr.join("-") );
Tip: check the returned array's length property to count the number of deleted elements.
var arr = [ "I", "learn", "JavaScript", "and", "it's", "fun" ];
arr.splice( 2, arr.length-1 ); // No need to capture deleted items
alert( arr.join("-") );
var arr = [ "I", "learn", "JavaScript", "and", "it's", "fun" ];
arr.splice( 3, 0, "as well as PHP" ); // Add 1 element before index 3
alert( arr.join(" ") ); // Show elements separated by space character
var arr = [ "I", "learn", "JavaScript", "and", "it's", "fun" ];
arr.splice( 4, 2, "it is", "hard" ); // Delete + replace last two
alert( arr.join(" ") ); // Show elements separated by space character
$arr = array( 'I', 'learn', 'PHP', 'today' );
// Remove last element and insert 3 new ones:
array_splice( $arr, 3, 1, array('and',"it's",'fun') );
print_r( $arr );
// Array( [0]=>I [1]=>learn [2]=>PHP [3]=>and [4]=>it's [5]=>fun )
Sister method: Array.slice(x,y) extracts elements from another array, from element X up to Y.