Javascript examples for Array:slice
Select elements using negative values:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from www . ja v a 2s .c o m*/ var fruits = ["A","B","C","D","E"]; var myBest = fruits.slice(-3, -1); document.getElementById("demo").innerHTML = myBest; } </script> </body> </html>