In this article, we are going to learn how the
includes() method works with
String. ES6 introduced this method to determine whether the specified sub-string in exists in given
String. It matches the
searchString – Required. String to search within str.
start – Optional. At which index the string search should be start. Default to 0 if not specified.
Boolean. If the match fount then it return
true else false.
Sample Code Snippet
The below example shows the how the includes() method works.
var str = "Hello Coder, welcome to the poopcode."; str.includes("code"); //true
For the String, “Hello Coder, welcome to the poopcode.” there is a sub-string “Code” and “code” in the below statement we specified the “Code” and index 12. From the position 12 we don’t found the exact match so it returns false.
var str = "Hello Coder, welcome to the poopcode."; str.includes("Code", 12); //false
Happy Learning 🙂