Check if a string starts with "world", starting the search at position 6: - Javascript String

Javascript examples for String:startsWith

Description

Check if a string starts with "world", starting the search at position 6:

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  w  w  .ja  v  a2 s  . c  om
    var str = "Hello world, this is a test.";
    var n = str.startsWith("world", 6);
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials