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

158
Vistas
Cannot read property 'length' of undefined. Also trim and strip is not a function

There is code:

function Hours(days){
  weekHours = 0;
  for(i = 0; i != days.length; i++){
    if(days[i].length > 3){
      dayHours = days[i].trim().split('-');
      weekHours += parseFloat(dayHours[1]) - parseFloat(dayHours[0]);
    }
  }
  return weekHours;
}

var fruits = [" 8-16  ",    " 8-23 ",   " 17-23 ",  " 16-23 ",  " 8-16 ", " 12-18 ",    " В "];

console.log(Hours(fruits));

Why i have this errors:

TypeError: Cannot read property 'length' of undefined

TypeError: days[i].trim is not a function

TypeError: days[i].strip is not a function

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's acting as if an undefined or null is in your fruits array. Did you have an extra comma in it originally, because the code works fine as-is.

Meaning,

var fruits = ['8-16',' B ']; is fine but

var fruits = ['8-16',,' B ']; is not.

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