Javascript examples for String:substring
If "start" is less than 0, it will start extraction from index position 0:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w ww.j a v a 2 s.c om var str = "Hello world!"; var res = str.substring(-3); document.getElementById("demo").innerHTML = res; } </script> </body> </html>