Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
get hostname but check if hostname has subdomain

I have to get a hostname without suffix and without subdomain.

exp:

URL: https://my-domain.com
URL2: https://my-domain.store.com

So I need only the my-domain how can I get this ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

checkout this

const url = new URL('http://example.com/path/index.html?param=value');
console.log(url.hostname) // gives example.com

and if it has a subdomain:

function getDomain(hostname) {
   hostname = hostname.split('.');
   hostname.reverse();
   return `${hostname[1]}.${hostname[0]}`;
}

url = new URL('http://test.example.com/path/index.html?param=value');
getDomain(url.hostname) // gives example.com

url = new URL('http://example.com/path/index.html?param=value');
getDomain(url.hostname) // gives example.com

taken from here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda