Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!