title: Switch statement for string matching in JavaScript
body: <p>How do I write a switch for the following conditional?</p>
  <p>If the url <strong>contains</strong> &quot;foo&quot;, then <code>settings.base_url</code> is &quot;bar&quot;.</p>
  <p>The following is achieving the effect required but I've a feeling this would be more manageable in a switch:</p>
  <pre><code>var doc_location = document.location.href;
  var url_strip = new RegExp(&quot;http:\/\/.*\/&quot;);
  var base_url = url_strip.exec(doc_location)
  var base_url_string = base_url[0];
  
  //BASE URL CASES
  
  // LOCAL
  if (base_url_string.indexOf('xxx.local') &gt; -1) {
      settings = {
          &quot;base_url&quot; : &quot;http://xxx.local/&quot;
      };
  }
  
  // DEV
  if (base_url_string.indexOf('xxx.dev.yyy.com') &gt; -1) {
      settings = {
          &quot;base_url&quot; : &quot;http://xxx.dev.yyy.com/xxx/&quot;
      };
  }
  </code></pre>