Javascript examples for Array:splice
At position 2, add the new items, and remove 1 item:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> var fruits = ["a","b","c","d","e"]; document.getElementById("demo").innerHTML = fruits; function myFunction() {/* w w w. j av a 2s. c o m*/ fruits.splice(2, 1, "Lemon", "Kiwi"); document.getElementById("demo").innerHTML = fruits; } </script> </body> </html>