title: Javascript get top domain from string
body: <p>I want to get the top domain from strings such as:</p>
  
  <pre><code>domain.com -&gt; domain.com
  subdomain.domain.com -&gt; domain.com
  subdomain.domain.co.uk -&gt; domain.co.uk
  </code></pre>
  
  <p>Have the following function so far:</p>
  
  <pre><code>function gdn(h) {
      return h.substring(h.lastIndexOf(".", h.lastIndexOf(".") - 1) + 1);
  }
  </code></pre>
  
  <p>Problem is that this does not work with <code>co.uk</code> domains. The return for:</p>
  
  <pre><code>hello.domain.co.uk -&gt; co.uk
  </code></pre>
  
  <p>Want it to be <code>domain.co.uk</code></p>
  
  <p>Any ideas?</p>