JavaScript Splice() method

 

Syntax

array.splice(index, howmany, item1, ....., itemX)

Parameters

ParameterDescription
indexRequired.
The position to add/remove items.
Negative value defines the position from the end of the array.
howmanyOptional.
Number of items to be removed.
item1, ..., itemXOptional.
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

Popular posts from this blog

Javascript Array Concat and Join Method

JavaScript While Loop

JavaScript pop() Method