W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 数组方法</h1> <h2>slice()</h2> <p>当给 slice() 方法赋予两个参数时,它从 <i>start</i> 参数中选择数组元素,直到(但不包括)<i>end</i> 参数:</p> <p id="demo"></p> <script> var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var citrus = fruits.slice(1,3); document.getElementById("demo").innerHTML = fruits + "<br><br>" + citrus; </script> </body> </html>