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