Remove hostname and port from URL using JavaScript

In this short article, we’ll show you how to remove hostname and port from URL using JavaScript. There are numerous possible techniques, but we’ll focus on two of them.

Different methods to remove hostname and port from URL

  1. Using Regular Expression
  2. Using URL API

1. Using Regular Expression

Let’s use the regular expression to remove the hostname and port from the URL.

2. Using URL API

Here, we will use the URL API to remove the hostname and port from URL.

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *