-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
  • 169,008
  • 28
  • 173
  • 236
deptdev
  • 67
  • 7

1 Answers1

-2

Try: window.location.origin

console.log(window.location.origin)
Elias
  • 125
  • 2
  • 22