JavaScript Splice() method
Syntax
array.splice(index, howmany, item1, ....., itemX)
Parameters
Parameter | Description |
index | Required. The position to add/remove items. Negative value defines the position from the end of the array. |
howmany | Optional. Number of items to be removed. |
item1, ..., itemX | Optional. New elements(s) to be added. |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Splice method </title>
</head>
<body>
<h1>Javascript Splice Method</h1>
<script>
// Aditya = Aditya Sharma
// array.splice(index, howmany deletes, item1, ....., itemX)
const myArr = ["Seema", "Aditya", "Reema", "Vandana"];
// myArr.splice(1,0, "Aditya Sharma");
// myArr.splice(2, 0, "Radha", "Radharani")
myArr.splice(0, 1, "Seema Sharma");
console.log(myArr);
</script>
</body>
</html>
Comments
Post a Comment