Javascript examples for String:slice
The slice() method returns the extracted parts in a new string.
Parameter | Description |
---|---|
start | Required. position to start the extraction. First character is at position 0 |
end | Optional. position up to, but not including where to end the extraction. |
If end is omitted, slice() selects all characters from the start-position to the end of the string
A String, representing the extracted part of the string
The following code shows how to Extract parts of a string:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w w w . jav a2s. co m*/ var str = "Hello world!"; var res = str.slice(-1); document.getElementById("demo").innerHTML = res; } </script> </body> </html>