JavaScript Array splice() method

The JavaScript array splice() method is used to add/remove elements to/from the given array.

Syntax:

array.splice (start,delete,element1,element2,...)

Parameters:
start: It is a required parameter and represents the index from where the function start to fetch the elements.
delete: It is a optional parameter and represents the number of elements which have to be removed.
element1,element2,… : It is a optional parameter which represent the elements which have to be inserted.

Returns:
A new array with removed elements.

Example:

<!DOCTYPE html>
<html>
<body>
<script>  
var a = ["GOLD","SILVER","DIAMOND","RUBY","PLATINUM"]
var result=a.splice(2,1,"BRONZE")  
document.writeln(a);  
</script>  
</body>
</html>

Output:

GOLD,SILVER,BRONZE,RUBY,PLATINUM
Please Share