0

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);
} 
4

1 Answer 1

3

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);
} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.