源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <h1>JavaScript slice()</h1> <p>此示例从数组元素3("Apple")中分割出数组的一部分 </p> <p id="demo"></p> <script> var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var citrus = fruits.slice(3); document.getElementById("demo").innerHTML = fruits + "<br>" + citrus; </script> </body> </html>
运行结果