How To Remove Elements In Array
With Slice method we can remove the Elements in Array .
The following code snippet is an Example of the Same.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to extract the second and the third elements from the array.</p>
By Clicking the following button we are calling the myFunction () Function .
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
now we have a variable "fruits " which contains the following Data .
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
With the slice method we can remove element in side an Array .
In the following example we want to remove one elements which is in the 1st and 3rd index position of the Array . It will slice that particular elements in and returns the balance elements which will be stored in "citrus ".
var citrus = fruits.slice(1, 3);
document.getElementById("demo").innerHTML = citrus;
}
</script>
</body>
</html>
The following code snippet is an Example of the Same.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to extract the second and the third elements from the array.</p>
By Clicking the following button we are calling the myFunction () Function .
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
now we have a variable "fruits " which contains the following Data .
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
With the slice method we can remove element in side an Array .
In the following example we want to remove one elements which is in the 1st and 3rd index position of the Array . It will slice that particular elements in and returns the balance elements which will be stored in "citrus ".
var citrus = fruits.slice(1, 3);
document.getElementById("demo").innerHTML = citrus;
}
</script>
</body>
</html>
Comments