Thursday, July 3, 2014

Javascript Function To Remove Array element by Index

function removeByIndex(arr, index) {
    arr.splice(index, 1);
}
 
test = new Array();
test[0] = 'Apple';
test[1] = 'Ball';
test[2] = 'Cat';
test[3] = 'Dog';
 
alert("Array before removing elements: "+test);
 
removeByIndex(test, 2);
 
alert("Array after removing elements: "+test);

No comments:

Post a Comment