To parse a URL in JavaScript, you can use the built-in URL object. This provides an easy way to extract and manipulate different parts of a URL.
Source code viewer
const url = new URL('https://example.com:8080/pathname/?search=test#hash'); // Accessing various parts of the URL console.log(url.protocol); // "https:" console.log(url.hostname); // "example.com" console.log(url.port); // "8080" console.log(url.pathname); // "/pathname/" console.log(url.search); // "?search=test" console.log(url.hash); // "#hash" console.log(url.origin); // "https://example.com:8080" console.log(url.href); // "https://example.com:8080/pathname/?search=test#hash"Programming Language: Javascript