Skip to content

Instantly share code, notes, and snippets.

@morrxy
Created March 15, 2018 08:12
Show Gist options
  • Save morrxy/53b8d2a6da7aee6757752788e19b328e to your computer and use it in GitHub Desktop.
Save morrxy/53b8d2a6da7aee6757752788e19b328e to your computer and use it in GitHub Desktop.
[获取host后两位] #javascript
function getDomain(host) {
var a = host.split('.')
var s = a.slice(a.length - 2)
return '.' + s.join('.')
}
getDomain(location.host)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment