运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <h2>The splice() Method</h2> <p>The splice() method adds new elements to an array, and returns an array with the deleted elements (if any):</p> <p id="demo1"></p> <p id="demo2"></p> <p id="demo3"></p> <script> const fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo1").innerHTML = "Original Array:<br> " + fruits; let removed = fruits.splice(2, 2, "Lemon", "Kiwi"); document.getElementById("demo2").innerHTML = "New Array:<br>" + fruits; document.getElementById("demo3").innerHTML = "Removed Items:<br> " + removed; </script> </body> </html>