Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
si la declaración no funciona y se vuelve indefinida

Tengo un código que agrega una clase en mi barra de navegación, esta clase se agregará solo en páginas específicas. Compruebo qué páginas son como esta pathName= window.location.pathname.split('/'); este código me devuelve una matriz con la ruta dividida, luego uso el ciclo foreach para verificar si esta página cumple con los requisitos. Si lo hace, la ruta será indefinida. Pero mi declaración if no funciona porque aparece este error Cannot read properties of undefined (reading '2')

El método en el que obtengo un camino.

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

Mi método de desplazamiento

 $(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 answers
Answer question

0

Resolví el problema, cambié mi declaración if a esta

Antes

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

Después

 $(window).scroll(function (evt) { if(typeof pathName[2]==='undefined') **to this**{ **something** }else{ **something** } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!