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

221
Visualizações
Can not check emptiness of array at index in Javascript

I have an array in Javascript. It looks like the one below.

source_array=[["A","B","C"],["A","B","C"],["A","B","C"]];

I create it by source_array.push(anotherArray). During the running of my code i remove entries from the indexes one by one by source_array[1].splice(0,1). So from [["A","B","C"],["A","B","C"],["A","B","C"]] i expect to get [["A","B","C"],["B","C"],["A","B","C"]];

If i do it enough times i should end up with [["A","B","C"],[],["A","B","C"]].

How to properly check if source_array[1] is now empty? It doesnt seem to work for me.

If (source_array[1] == undefined) this turns out FALSE instead of TRUE. It gives out FALSE only after i am done removing the items. It works well if i check for source_array[2] in a source_array[["A","B","C"],["A","B","C"]]

I think i tried everything i found online.

I feel it will be something basic, but i am an amateour and this...beats me.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

While the array is empty, it's not undefined.

Always check the array's length property to determine whether a targeted array is empty.

Thus:

let arr = [];
let arr2 = ['foo', 'bar'];

arr.length === 0;  // true, empty
arr2.length === 0; // false, populated
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