Switch statement for string matching in JavaScript

前端 未结 9 1486
深忆病人
深忆病人 2020-11-29 15:46

How do I write a swtich for the following conditional?

If the url contains \"foo\", then settings.base_url is \"bar\".

The following is achi

9条回答
  •  眼角桃花
    2020-11-29 16:34

    Just use the location.host property

    switch (location.host) {
        case "xxx.local":
            settings = ...
            break;
        case "xxx.dev.yyy.com":
            settings = ...
            break;
    }
    

提交回复
热议问题