includes method checks a provided string against the calling String object, it returns
true if the calling String object contains the provided string and
false otherwise. If no arguments are provided, the method returns
""welcome to scotch"".includes(""scotch"") // true
// New string to test let string = "are you available for the meetup?" const searchWord = "meetup" const isPresent = string.includes(searchWord) console.log(isPresent) // true
The .includes() method is case sensitive
- Takes a string as a parameter.
- Checks the provided string against the calling string object.
trueif the calling string contains the provided string and
const isPresent = string.includes(searchString, startPosition)
This is a string to be checked against the calling string object -
This is an integer specifying the position within the string where the search begins -
Returns a boolean,
true if the calling string contains the provided string,
.includes() method can be used to search a list of comma separated values in a string.
// List of names const names = "mike, chris, perry, john, liz" // Name to be searched let name = "chris" // Search for name let isPresent = names.includes(name) // Log result console.log(isPresent) // true
Want to improve your coding and design skills?
I'm continually researching the best practices and tools for coding.
Join 50,000+ developers looking to make cool stuff.
We value your privacy. 1-click unsubscribe.
Chris Sev is the co-founder of Better Dev. Coding better every day. Previously he created Scotch.io which was acquired.
What did you think of the article? Let us know!
(these comments are powered by GitHub issues and use 0 trackers)