3

I'd like to achieve that, if "clientpsseabq" string is contained in variable Var_words then equal true, else false. I just have no idea what method or function do I need to use?

var Var_words = "https://www.go.me/outputsearchs/clientpsseabq"

if ( Var_words contains string "`clientpsseabq`"){
   return true;
}else{
   return false;
}

if someone could help me how can I complete this task?

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
olo
  • 5,225
  • 15
  • 52
  • 92

4 Answers4

3

You can try this

if (Var_words.indexOf("clientpsseabq") >= 0)

or with care of case sensitivity

if (Var_words.toLowerCase().indexOf("clientpsseabq") >= 0)
{
   // your code
}
Sachin
  • 40,216
  • 7
  • 90
  • 102
3

Use the (native JavaScript) function String.indexOf():

if(Var_words.indexOf('clientpsseabq') !== -1) {
    return true;
} else {
    return false;
}

.indexOf() returns the index of the string. If the string is not found, it returns -1.

A smaller, cleaner solution would be to simply return the value of the conditional directly:

return (Var_words.indexOf('clientpsseabq') !== -1);
Bojangles
  • 99,427
  • 50
  • 170
  • 208
1
 if(Var_words.indexOf("clientpsseabq") >= 0))
 {

 }
andy
  • 5,979
  • 2
  • 27
  • 49
Mahesh Patidar
  • 184
  • 3
  • 15
1

use a regular expression to test for the case

if(/clientpsseabq/.test(Var_words)){
    //given string exists
} else {
    //given string does not exists
}
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531