Docs

URL.prototype.hostname

The hostname of the URL.

Example

let url = new URL("https://example.com:8080/path")
url.hostname
"example.com"
let url = new URL("https://example.com")
url.hostname = "test.com"
url.href
"https://test.com"