-1
function functiont(){
    var a = document.getElementById("q").value;
    var b = a.toLowerCase();
    var x = b.search("news"||"headline"||"headlines");//is this possible?
    if(x != -1){
        $("p").text("here are the results");
    } else{
        $("p").text("sorry");
    }

Is the following thing possible or I have to create more variables and search for all the keywords?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Sarthak Singhal
  • 161
  • 1
  • 11
  • 2
    Possible duplicate of [How do you search multiple strings with the .search() Method?](http://stackoverflow.com/questions/12251197/how-do-you-search-multiple-strings-with-the-search-method) – JJJ May 07 '17 at 11:54

1 Answers1

3

You can use regular expressions in the search method:

b.search(/news|headline|headlines/);

https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/String/search

Benedikt
  • 517
  • 4
  • 18