how to compare two strings in javascript if condition

前端 未结 4 1599
长情又很酷
长情又很酷 2020-12-30 12:17

I\'m having trouble recalling how to compare these two strings in an if statement. What I\'m string to do is check if my variable compare equals page1

4条回答
  •  伪装坚强ぢ
    2020-12-30 12:36

    Try

    if( ["page1", "page2"].includes(compare) ){...}
    

    var compare = "page3";
    
    if( ["page1", "page2"].includes(compare) ) {
      document.body.innerHTML = "github url";
    } else {
      document.body.innerHTML = "non-github url";
    }

提交回复
热议问题