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

125
Views
Correct way to capture `host` portion of fully qualified domain name

I have a hostName string which may or may not be a fully qualified domain name.

hostName = host1.abc.com  OR

hostName = host1

In case hostName is a fully qualified domain name, then I need to capture only the first portion in host

host = host1

I have written the following but it is giving empty string "" when the hostName is not a fully qualified domain name

const host = hostName.substring(0, hostName.indexOf('.'));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This way it will give the hostname correctly, in any of the 2 scenarios

const host = hostName.split('.')[0];

Or else

const idx = hostName.indexOf('.');

const host = idx > 0 ? hostName.substring(0, idx) : hostName;

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!