Skip to content

Instantly share code, notes, and snippets.

@panchalkalpesh
Created April 30, 2024 20:30
Extract Top Level Domain Name in JavaScript
const extractTLD = (href = window.location.href) => {
const url = new URL(href);
return url.hostname.split('.').slice(-2).join('.');
}
export default extractTLD;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment