title: Split URL into array and then change url depending on language
body: <p>I'm looking to change the url depending on if the site is loaded on a different language. I think I'm close.</p>
  <p>The is the check if the site is just .com (if that's the case leave it alone) OR .com/fr/slug .com/de/slug .com/es/slug turns into .com/fr .com/de ...</p>
  <p>The english site. One that's just .com/slug is .com//slug. Looking to fix that</p>
  <pre><code>   // take url and put into array
      var pathArray = window.location.pathname.split('/');
      var newPathname = &quot;&quot;;
      for (i = 0; i &lt; pathArray.length; i++) {
        // if statement to prevent extra '/' at end of url
        if (i &lt; 2 ){
          newPathname += pathArray[i] + &quot;/&quot;;
        }
      }
      newPathname.toString();
  
      if (newPathname == &quot;/de/&quot; || &quot;/fr/&quot; || &quot;/es/&quot; || &quot;/ja/&quot; || &quot;/zh-hant/&quot;){
        var newURL = window.location.host + newPathname;
      console.log(newURL);
      document.querySelector(&quot;.navbar__logo__wrapper&quot;).href = newURL;
      }
      }
  
  </code></pre>