get domain name javascript code example
Example 1: javascript get current url
var currentUrl = window.location.href;
Example 2: get domain name javascript
window.location.hostname
Example 3: javascript get domain name from string
const url = 'https://www.mydomain.com/blog?search=hello&world';
const domain = (new URL(url)).hostname.replace('www.','');