The includes() method determines whether a string contains the characters of a specified string.
The includes() method determines whether a string contains the characters of a specified string.
It returns true if the string contains the characters, and false if not.
The includes() method is case sensitive.
string.includes(searchvalue,start)
Parameter | Require | Description |
---|---|---|
searchvalue | Required. | The string to search for |
start | Optional. | Default 0. At which position to start the search |
A Boolean. Returns true if the string contains the value, otherwise it returns false
Check if a string includes "world":
//check where if the string includes the specified value. var str = "Hello world this is a test."; var n = str.includes("world"); console.log(n);// www.j a v a2 s . com //Check if a string includes "world", starting the search at position 12: //check where if the string includes the specified value. str = "Hello world, welcome to the universe."; n = str.includes("world", 12); console.log(n);