Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
How to get subdomain from url

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?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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]);

about 4 years ago · Juan Pablo Isaza Report

0

"http://abc.xyz.com".split(".")[0]
// or
var url = "http://abc.xyz.com";
url.split(".")[0]

returns "http://abc"

about 4 years ago · Juan Pablo Isaza Report

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);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!