I need to check whether a string contains another string or not?
var str1 = "ABCDEFGHIJKLMNOP";
var str2 = "DEFG";
Which function do I use to find out if str1 contains str2?
This question is related to
javascript
jquery
string
comparison
contains
var str1 = "ABCDEFGHIJKLMNOP";
var str2 = "DEFG";
sttr1.search(str2);
it will return the position of the match, or -1 if it isn't found.
If you are worrying about Case sensitive change the case and compare the string.
if (stringvalue.toLocaleLowerCase().indexOf("mytexttocompare")!=-1)
{
alert("found");
}
Please try:
str1.contains(str2)
I use,
var text = "some/String";
text.includes("/") <-- returns bool; true if "/" exists in string, false otherwise.
Source: Stackoverflow.com