Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[JavaScript] Extract hostname from string

https://stackoverflow.com/questions/8498592/extract-hostname-name-from-string

const getHostname = (url) => {
  // use URL constructor and return hostname
  return new URL(url).hostname;
}

let hostname = getHostname("https://google.com");
console.log(hostname); //google.com

Leave a Reply

Your email address will not be published. Required fields are marked *