Prev Demo
Slice() Method For Removing And Adding New Element In First Position Of An Array In Javascript
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <p>Click the button to remove and add a new element to the array.</p> <button onclick="myFunction()">Click</button> <p id="myId"></p> <script> var a = ["India", "Pakisthan", "Bangladesh", "China", "Australia", "England"]; document.getElementById("myId").innerHTML = a; function myFunction() { a.splice(1, 1, "SriLanka"); document.getElementById("myId").innerHTML = a; } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output