Prev Demo
JavaScript
>
Slice() Method For Returning The Selected Elements In Javascript
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <p>Click the below to show the select the city related to country.</p> <input type="button" onclick="myValue()" value="Return"/> <p id="myId"></p> <script> function myValue() { var a = ["India", "Mumbai", "Pakisthan", "Karachi", "Malaysia", "Abudhabi"]; var b = a.slice(0, 4); document.getElementById("myId").innerHTML = b; } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output