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

106
Visualizações
Seemingly empty Array after push

I'm just trying to search through a two dimensional array of strings.

The results in found are correct, but the row isn't pushed (correctly) into the array.

The browser shows me this:

enter image description here

function filterItems(arr, query) {
  return arr.filter(function(el) {
    return el.toLowerCase().includes(query.toLowerCase());
  });
}

function FilterArray(unfiltered_array, searchphrase) {
  var filtered_array = [];
  for (var i = 0; i < unfiltered_array.length; i++) {
    var row = unfiltered_array[i];
    var found = filterItems(row, searchphrase);

    if (found.length) {
      console.log(row);
      filtered_array.push(row);
    }
  }


  return filtered_array;

}

const filtered = FilterArray([
  ["LC53005", "bob", "lc56778"],
  ["FP53001", "john", "dog"]
], "lc5");

console.log({
  filtered
});

and I was searching for LC53005.

Any ideas?

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

0

Clearer approach with the expected result !

var unfiltered_array = [
  ["LC53005", "bob", "cat"],
  ["FP53001", "john", "dog"]
];

function filterItems(arr, query) {

  return arr.filter(function(el) {
    return (el.toLowerCase().includes(query.toLowerCase()));
  })
}

function FilterArrayMap(unfiltered_array, searchphrase) {
  return unfiltered_array.map(k => {
    return filterItems(k, searchphrase);
  }).flat();
}

console.log(FilterArrayMap(unfiltered_array, "LC53005"));

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