Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda