Usually, I would expect a String.contains()
method, but there doesn't seem to be one. What is a reasonable way to check for this?
Join them; it only takes a minute:
|
||||
If you don't like the
|
|||||||||
|
This is a function to check if a substring is existing in a string or not:
|
|||||
|
I know that best way is I suggest another way(
|
||||
|
Try this:
Here is an example: jsfiddle |
||||
|
You can use
|
||||
|
You can also do something like this
|
|||||
|
One more Function
|
|||||
|
There are multiple ways to do this. But most of the time, you will be fine using the
|
||||
|
With ECMAScript 2015, we can use
|
|||||
|
|
||||
|
protected by Sean Vieira Nov 2 '12 at 12:31
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
r.indexOf(s) !== -1;
fastest than others. hayageek.com/javascript-string-contains – Sherali Turdiyev Oct 1 '15 at 5:37"foo bar".match('oo') ? console.log("contained") : console.log("not contained");
– Alejandro Vales May 24 at 10:51includes()
method for strings in ECMA6. Supported by everyone except IE. A good polyfill is available in Mozilla's docs: developer.mozilla.org/en/docs/Web/JavaScript/Reference/… – K48 Oct 3 at 11:49