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

187
Vistas
filtering an array of objects that has nested arrays, with an array of values

I have an array "link" of objects, the objects have a feild that is another array. Then I have an array "valuesAces" of strings

I would like to filter "links" in order to get the objects that have at least one of the values in "valuesAces".

In the following example , "linksFiltered" needs to end up being :

[
{aces:['A','B']},{aces:['A','C','D']},{aces:['B']},{aces:['D','B']}
]

Example :

let links = [
{aces:['A','B']},{aces:['A','C','D']},{aces:['B']},{aces:['D','C']},{aces:['D','B']}
]

let valuesAces = ['A','B']


linksFiltered = links.filter(link => { return 
 [...link.aces].some(ace => valuesAces.includes(ace)
 )})

I am apparently doing something wrong as the result is not the one expected. Any advicewill be very appreciated

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0


const links = [
    {aces:['A','B']},
    {aces:['A','C','D']},
    {aces:['B']},
    {aces:['D','C']},
    {aces:['D','B']}
]

const valuesAces = ['A','B']


const linksFiltered = links.filter(link => link.aces.some(ace => valuesAces.includes(ace)))

about 4 years ago · Juan Pablo Isaza Denunciar

0

First off, you're missing commas in your links

let links = [
  {aces:['A','B']},
  {aces:['A','C','D']},
  {aces:['B']},
  {aces:['D','C']},
  {aces:['D','B']}
]

Then you had one extra ) after .includes(ace)))). It should be:

let valuesAces = ['A','B']

linksFiltered = links.filter(link => { return (
 ([...link.aces].some(ace => valuesAces.includes(ace)))
)})

But why are you putting so many parentheses? This is the same code:

linksFiltered = links.filter(l => l.aces.some(a => valuesAces.includes(a)))

Finally, for better readability, you can change it to:

const inValuesAces = x => valuesAces.includes(x) 
 
linksFiltered = links.filter(l => l.aces.some(inValuesAces))

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