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

169
Visualizações
Splice array rows if they have indexOf

I have these rows and want to delete all rows that have cell containing "undefined"

"rows":[
[0,"Peter", "undefined value"],
[3,"John", 90909090],
[5,"Mary","undefined"]
]

So, I need to remove rows 1 and 3

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

0

just use filter

let rows = [
  [0, 'Peter', undefined],
  [3, 'John', 90909090],
  [5, 'Mary', undefined],
];

rows = rows.filter((row) => {
  return row.indexOf(undefined) === -1;
});

console.log(rows); // [ [ 3, 'John', 90909090 ] ]

if you mean that delete the array if it has a string cell contain 'undefined' as string you can go with this

let rows = [
  [0, 'Peter', 'undefined value'],
  [3, 'John', 90909090],
  [5, 'Mary', 'undefined'],
];

rows = rows.filter((row) => {
  let isContainUndefined = false;
  row.forEach((element) => {
    if (String(element).includes('undefined')) {
      isContainUndefined = true;
      return;
    }
  });
  return !isContainUndefined;
});

console.log(rows); // [ [ 3, 'John', 90909090 ] ]
about 4 years ago · Juan Pablo Isaza Relatório

0

With filter, then some on each item which is truthy if none of the items in each array includes undefined (string).

let rows = [
  [0, "Peter", "undefined value"],
  [3, "John", 90909090],
  [5, "Mary", "undefined"]
];

rows = rows.filter(row => !row.some(v => typeof v === 'string' && v.includes('undefined')));

console.log(rows); // [ [ 3, 'John', 90909090 ] ]

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