You can use Show
Based on the docs,
Which you can use it this way.
Or you can write a function for it
This post will discuss how to check whether a string contains another string as its substring in JavaScript. 1. Using String.prototype.includes() functionThe includes() method can be used to check whether a given string includes another string or not. It returns
Download Run Code
2. Using Lodash LibraryIf you are using lodash library, the _.includes method will be useful:
Download Code 3. Using String.prototype.indexOf() functionThe indexOf() method returns the index of the first occurrence of the target or
Download Run Code 4. Using String.prototype.search() functionFinally, you can also use the search() method to check if the source string contains the target string. The following example would return the index of the first match of the target in the given string, or
Download Run Code That’s all about determining whether a string contains another string as a substring in JavaScript. How do you check if a string contains another string in JavaScript?The includes() method returns true if a string contains a specified string. Otherwise it returns false .
How do you check if a string contains another string?You can use contains(), indexOf() and lastIndexOf() method to check if one String contains another String in Java or not. If a String contains another String then it's known as a substring. The indexOf() method accepts a String and returns the starting position of the string if it exists, otherwise, it will return -1.
What does .includes do in JavaScript?The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
How do you equate two strings in JavaScript?To compare two strings in JavaScript, use the localeCompare() method. The method returns 0 if both the strings are equal, -1 if string 1 is sorted before string 2 and 1 if string 2 is sorted before string 1.
|