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

202
Visualizações
if statment not working and getting undefined

I have a code which add a class on my navbar, this class will be added only on specific pages. I check which pages like this pathName= window.location.pathname.split('/'); this code returns me an array with the splited path, then I use the foreach loop to check if this page matches the requirements. If it does, the path will be undefined. But my if statment doesn't work because, I get this error Cannot read properties of undefined (reading '2')

The method where I'm getting a path

let pathName;
$(window).on('load', function () {
    if($('.owl-item').length<5){
    }
    pathName= window.location.pathname.split('/');
}

My scrolling method

$(window).scroll(function (evt) {
        if(pathName[2]===undefined) the line where I getting the error{
            **something**
            }else{
                **something**
            }
        }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have solved the problem I changed my if statment to this

Before

$(window).scroll(function (evt) {
        if(pathName[2]===undefined) **this** {
            **something**
            }else{
                **something**
            }
        }

After

$(window).scroll(function (evt) {
        if(typeof pathName[2]==='undefined') **to this**{
            **something**
            }else{
                **something**
            }
        }
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