Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda