Javascript examples for String:substr
Extract only the first character:substr(0, 1)
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// www . jav a2 s .co m var str = "Hello world!"; var res = str.substr(0, 1); document.getElementById("demo").innerHTML = res; } </script> </body> </html>