How to Change Script Src Dynamically using JavaScript

                             *****                        
   On - 2023
   By - Apu Gorai
To remove an item from a JavaScript array by index, you can use the splice() method. This method takes two arguments: the index of the item you want to remove, and the number of items you want to remove.

For Example :

<script>
 let myArr = [1, 2, 3, 4, 5];
     myArr.splice(3, 1);
// output :- [1, 2, 3, 5]
</script>
Using .indexOf() and .splice() - This method requires you to first find the index of the item you want to remove, then pass that index to the splice() method to remove the item.

For Example :

<script>
 let myArr = [1, 2, 3, 4, 5];
 let myIndex = myArr.indexOf(4);
     myArr.splice(index, 1);
// output : [1, 2, 3, 5]
</script>
Using .filter() - This method creates a new array without the item you want to remove. For example:
<script>
 let myArr = [1, 2, 3, 4, 5];
 let newArr = myArr.filter(item => item !== 4);
 // output : [1, 2, 3, 5]
</script>
Using a For Loop - This method iterates through the array and removes the item when it is found. For example:
<script>
 let myArr = [1, 2, 3, 4, 5];
 for (let i = 0; i < myArr.length; i++) {
  if(myArr[i] === 4) {
    myArr.splice(i, 1);
  }
}
// output : [1, 2, 3, 5]
</script>
Using Array.prototype.slice() - This method creates a new array without the item you want to remove. For example:
<script>
 let myArr = [1, 2, 3, 4, 5];
 let newArr = myArr.slice(0, 3).concat(myArr.slice(4));
// output : [1, 2, 3, 5]
</script>
Read More»