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

201
Vistas
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 Respuestas
Responde la pregunta

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 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