Remove hostname from URL in javascript

Updated at 28-Sep-2021, By samar

Remove hostname from URL in javascript

In this session, we are going to try to solve the "Remove hostname from URL in javascript" puzzle by using the computer language.

You can remove hostname from URL in javascript. Sometimes you have to remove the hostname from the URL in that case it will help you to remove the hostname (domain name) from the URL in javascript
  • Remove hostname from url in javascript using URL() constructor

    <script>
    var url = new URL('https://w3codegenerator.com/queries/javascript')
    console.log(url.pathname) 
    </script>
    

    Output:

    /queries/javascript

    This code snippet return the url with pathname (without hostname) using URL() constructor method.

Back to code snippet queries related javascript