If "start" is less than 0, it will start extraction from index position 0: - Javascript String

Javascript examples for String:substring

Description

If "start" is less than 0, it will start extraction from index position 0:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials