Javascript Splice() Function

The splice() function of array object adds and/or removes elements from an array and return array containing the deleted elements. Use it for example to add or remove element of existing array.

Syntax

arr.splice(start, deleteCount[, item1[, item2[, ...]]])

Javascript Splice() Function Example

<html>
<head>
<script type="text/javascript">
// Create an array.
var arr = [4, 11, 2, 10, 3, 1];
var newArray = arr.splice(2,2,22,23);
document.write(newArray);
document.write("<br/>" + arr);
</script>
</head>
<body>
</body>
</html>

This will produce following result

2,10
4,11,22,23,3,1