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

146
Visualizações
search in array in arry of objects by single character

How to search in an array inside the array of the object by one single character

    const arr = [{ x: 1, tags: ["tag1", "taf", "ee", "xx"] },{ x: 3, tags: ["ta", "e", "xx"] }];

const fResult = arr.filter((res) => res.tags().includes("tag1"));

this will return the value if we input a full tag1 word, not just "t" or "ta"

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

0

If you want to match that the value starts with it then you want to use some()

const filterIt = (arr, text) => arr.filter(
  (res) =>
  res.tags.some(
    val => val.startsWith(text)
  )
);

const arr = [{
  x: 1,
  tags: ["tag1", "taf", "ee", "xx"]
}, {
  x: 3,
  tags: ["ta", "e", "xx"]
}];

console.log("t", filterIt(arr, "t"));
console.log("ta", filterIt(arr, "ta"));
console.log("tag", filterIt(arr, "tag"));

about 4 years ago · Juan Pablo Isaza Relatório

0

finally figured out this simple solution

by converting the array of tags to string, then checking by including is solve everything

    const arr = [{ x: 1, tags: ["tag1", "taf", "ee", "xx"] },{ x: 3, tags: ["ta", "e", "xx"] }];

here is the solution const fResult = arr.filter((res) => res.tags.toString().includes("tag1"));

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