Open this example in the interactive library
Source code
const url = new URL("https://example.com/docs?q=js#arrays");
console.log(url.hostname, url.pathname, url.searchParams.get("q"));
Sample output
example.com /docs js

Open this example in the interactive library
const url = new URL("https://example.com/docs?q=js#arrays");
console.log(url.hostname, url.pathname, url.searchParams.get("q"));
example.com /docs js