W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 数组</h1> <p>请单击按钮,以使用负数参数提取第三个和第四个元素。</p> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var myBest = fruits.slice(-3, -1); document.getElementById("demo").innerHTML = myBest; } </script> </body> </html>