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

190
Vistas
Page path value - JS variable

I have to return site type (business or personal) value from page path

The function I use is:

    function currentPath() {
      var siteType=window.location.pathname;
      if ( siteType.indexOf('business')) {
        siteType= 'business';
      } else {
        siteType = 'personal';
      }
      return siteType;
    }

So if page path contains "business", it should return business and if it does not contain "business" it should return "personal".

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

0

Use includes()

function currentPath() {
  var siteType = window.location.pathname;
  if (siteType.includes('business')) {
    return 'business';
  } else {
    return 'personal';
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

indexOf

function currentPath() {
  var siteType=window.location.pathname;
  if ( siteType.indexOf('business') !== -1) { //return -1 if not present
    siteType= 'business';
  } else {
    siteType = 'personal';
  }
  return siteType;
}

or

includes

function currentPath() {
  var siteType=window.location.pathname;
  if (siteType.includes('business')) { //checks for the string in the given string or array
    siteType= 'business';
  } else {
    siteType = 'personal';
  }
  return siteType;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use includes() method with conditional operator:

function currentPath() {
  return window.location.pathname.includes('business') ? 'business' : 'personal';
}
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