-1

I have a string in javascript that is a url.

Example

https://www.example.local/cars/bmw/12312?exp=2

I want to extract just the domain, no matter what the url path is. For example, all I want is

https://www.example.local no matter what the url paths / query params are.

How would I do this.

mplungjan
  • 155,085
  • 27
  • 166
  • 222
deptdev
  • 37
  • 3

1 Answers1

-1

Try: window.location.origin

console.log(window.location.origin)
Elias
  • 358
  • 1
  • 19