Delete the april month from an array using Splice Method and indexOf method

 <!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>Delete the april month from an array using Splice Method and indexOf method</h1>
  <script>
 
    const arrMonths = ['jan', 'feb', 'march', 'april', 'may'];
    // arrMonths.splice(3, 1);
    console.log(arrMonths);

    const deleteApril = "march";
    const delIndex = arrMonths.indexOf(deleteApril);
    console.log(`Index of ${deleteApril} = ${delIndex}`);

    if(delIndex!= -1){
      arrMonths.splice(delIndex, 1);
      console.log(arrMonths);
    }else{
      console.log("Elemen not found");
    }



   

   


  </script>
</body>

</html>

Comments

Popular posts from this blog

Javascript Array Concat and Join Method

JavaScript While Loop

JavaScript pop() Method