How to find the domain name from the current page’s URL in JavaScript?

Sometimes, we want to find the domain name from the current page’s URL in JavaScript.

In this article, we’ll look at how to find the domain name from the current page’s URL in JavaScript.

How to find the domain name from the current page’s URL in JavaScript?

To find the domain name from the current page’s URL in JavaScript, we can use the location.hostname property.

For instance, we write:

console.log(location.hostname)

to get the domain name part of the current page URL.

Conclusion

To find the domain name from the current page’s URL in JavaScript, we can use the location.hostname property.