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

100
Vistas
Undefined properties in array split

So, I have this here function designed to split the array elements and return them to two separate arrays. Problem is, when I try yo run it it returns "Challenges.js:32 Uncaught TypeError: Cannot read properties of undefined (reading 'split')" I don't really get it, what am I missing here? Sorry for the noob question, been studying for less than two weeks :D

const array0 = [
    "3:1",
    ...
    "4:0",
  ];
let array1 = [];
let array2 = [];

for (let i = 0; i <= array0.length; i++) {
    array1.push(array0[i].split(":")[0]);
    array2.push(array0[i].split(":")[1]);
  }
  
  console.log(array1, array2);
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The condition of for loop should be i < array0.length instead of i <= array0.length

about 4 years ago · Juan Pablo Isaza Denunciar

0

your for loop is wrong, it should be

for (let i = 0; i < array0.length; i++) {

}

and not

for (let i = 0; i <= array0.length; i++) {

}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to change that <= to < or add -1 after array0.length:

for (let i = 0; i < array0.length; i++) {
    array1.push(array0[i].split(":")[0]);
    array2.push(array0[i].split(":")[1]);
  }

both ok

for (let i = 0; i < array0.length -1; i++) {
    array1.push(array0[i].split(":")[0]);
    array2.push(array0[i].split(":")[1]);
  }
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