String includes() Method - Javascript String

Javascript examples for String:includes

Description

The includes() method returns true if the string contains the specified characters, and false if not.

The includes() 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 contains the value, otherwise it returns false

The following code shows how to Check if a string includes "world":

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 a 2  s.co m
    var str = "Hello world world world";
    var n = str.includes("world", 12);
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials