JavaScript Array splice()

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 starts to fetch the elements. delete: It is an optional parameter and represents the number of elements that have to be removed. element1,element2,… : It is an optional parameter that represents the elements that 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>
Please follow and like us:
Content Protection by DMCA.com