0

I have a url like http://abc.xyz.com. I just want 'http://abc' part, But I am getting 'http://abc.xyz.com'

I tried this:

windw.location.origin

Do I need to write some extra method to get the first part of url or is there something any window method which will do the same?

techguy
  • 71
  • 8

3 Answers3

2

You can split it by . and take the first element

window.location.origin.split('.')[0]

Example:

console.log(window.location.origin);
console.log(window.location.origin.split('.')[0]);
jabaa
  • 5,844
  • 3
  • 9
  • 30
0
"http://abc.xyz.com".split(".")[0]
// or
var url = "http://abc.xyz.com";
url.split(".")[0]

returns "http://abc"

Sli4o
  • 245
  • 1
  • 8
0

It's as simple as that: [subdomain] = 'https://abc.def.xyz'.split('.');

var url = 'https://abc.def.xyz';
[subdomain] = url.split('.');
console.log(subdomain);
Reflective
  • 3,854
  • 1
  • 13
  • 25