Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda