Note: The JS includes() method is case sensitive
- searchvalue: The string to search for.
- start: At which position to start the search, optional and the default value is 0.
It will return true if string included else false indicating the absence.
Let’ see an example of the string contains a character or not in JS using the includes() method.
Let’s see if a string includes “world”:
<!DOCTYPE html> <html> <head> <script> var str = "Hello world, welcome to the EyeHunts.com"; var n = str.includes("world"); alert(n) </script> </head> </html>
Same example with starting the search at position 10:
It will return false because “world” word will not found after 10 portion.
<!DOCTYPE html> <html> <head> <script> var str = "Hello world, welcome to the EyeHunts.com"; var n = str.includes("world", 10); alert(n) </script> </head> </html>
Do comment about this tutorial. If any suggestions and example then do comment.
Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.