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

165
Views
No se puede leer la propiedad 'dividir' de jquery indefinido

Hola chicos, estoy tratando de crear una función para obtener el enlace completo si tiene #mystring existe, por ejemplo.

www.mydomian.com/#mystring&........ .

pero cuando divido me muestra errores

TypeError no capturado: no se puede acceder a la propiedad "dividir", los datos [1] no están definidos

 function my_function() { var link = window.location +''; // get website link as string www.mydomain.com var data = link.split("#"); // start link after # for example www.mydomain.com/#mystring&anotherstring=hello var widget_type = data[1].split("&")[0]; // to get "mystring" if(widget_type == 'mystring') { // check if "mystring" in the link exists var link = window.location.hash.substr(1); // get full link console.log(link) } } my_function();

Entonces, ¿cómo puedo verificar si "#mystring" sale en mi enlace antes de hacerlo y corregir el error de división?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si el link no contiene # , la matriz data después de la división contendrá solo un elemento, que es el link , por lo que debe verificar si hay un segundo elemento en los data mediante el encadenamiento opcional después data[1]

 var widget_type = data[1]?.split("&")[0]

O puede usar la condición if .

 const path = data[1] var widget_type = ''; if (path) { widget_type = path.split("&")[0]; }
about 4 years ago · Santiago Trujillo 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!