String startsWith() Method - Javascript String

Javascript examples for String:startsWith

Description

The startsWith() method checks if a string begins with given characters.

The startsWith() method is case sensitive.

Parameter Values

Parameter Description
searchvalue Required. The string to search for
start Optional. Default 0. At which position to start the search

Return Value:

A Boolean. Returns true if the string starts with the value, otherwise it returns false

check where if the string starts with the specified value.

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.java2  s .  c om*/
    var str = "The following code shows how to ";
    var n = str.startsWith("The", 6);
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials