How do I parse a URL into hostname and path in javascript?

Bite Code
Published on Apr, 12 2024 1 min read 1 comments
image

I would like to take a string

var a = "http://example.com/aa/bb/"

and process it into an object such that

a.hostname == "example.com"

and

a.pathname == "/aa/bb"
1 Answers

Mahabubur Rahman Apr 12, 2024 - 07:15 PM