I have this code. I am using contains function to check if the value stored in the string or not but getting error. can anyone help me how to check this.
var lang = reply.LANGUAGES[InstObj.langId];
var instElement = reply.QUAL[iCount] ;
if(instElement.contains(lang))
{
alert(lang);
}
else
{
alert(instElement);
}
asked Dec 20, 2013 at 11:23
Rahul Pandey
4551 gold badge4 silver badges13 bronze badges
1 Answer 1
Use indexOf()
The indexOf() method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex, returns -1 if the value is not found.
Change your code as
var lang = reply.LANGUAGES[InstObj.langId];
var instElement = reply.QUAL[iCount] ;
if(instElement.indexOf(lang) > -1)
{
alert(lang);
}
else
{
alert(instElement);
}
answered Dec 20, 2013 at 11:26
Satpal
134k13 gold badges168 silver badges171 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
indexOfcontains()coming soon, but currently few browsers support it.containsmethod in jQuery tho. That's specifically a DOM method.