JavaScript String includes() Method
You are Here:
JavaScript String includes() Method
The includes()
method returns a Boolean value indicates whether one string may be found within another string.
Note: This method is case sensitive.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var str = "Hello there my old friend"
var result = str.includes("fri");
document.write(result);
</script>
</body>
</html>
Syntax
str.includes(searchString, startFrom)
Parameter Values
Value | Type | Explanation |
---|---|---|
searchString | Required | Specifies the characters to be searched for within this string. |
startFrom | optional | Specifies the starting position of a string (str). If omitted, the default value is '0'. |
Return Values
Value | Explanation |
---|---|
true | If the search string is found anywhere within the given string. |
false | If the search string is not found anywhere within the given string. |
includes() with Specified Starting Position
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var str = "Hello there my old friend"
//str = "e my old friend"
var result = str.includes("Hello", 10);
document.write(result);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.