how to compare two strings in javascript if condition

前端 未结 4 1624
长情又很酷
长情又很酷 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:38

    a.localeCompare(b) is another cool way of comparing larger strings

    function areEqual(a, b){
    
    
      if (a.length !== b.length) {
             return false;
      }
    
      return a.localeCompare(b) === 0;
    }
    
    
    if(areEqual(a,b)){...}
    

提交回复
热议问题