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

170
Views
filtering an object array on a feild that is an array , by using an array

Lets say I have the two following arrays. The goal here is to filter "foods" array with the values of "tagsValues". I want to return a new array of foods, where foods.tags include one or several items from tagsValues.

const tagsValues = ['gluten-free', 'carb-free', 'flavor-free'];
const foods = [
  { name: 'pasta', tags: ['delicious', 'has carbs']}, 
  { name: 'gluten-free-pizza', tags: ['gluten-free']}, 
  { name: 'soda', tags: ['delicious', 'has sugars']}, 
  { name: 'pizza', tags: ['delicious', 'best meal of the year','carb-free']},
  { name: 'rice cakes', tags: ['flavor-free','carb-free']}
]

In this example , I need to get the following result :

result = [ 
  { name: 'gluten-free-pizza', tags: ['gluten-free']}, 
  { name: 'pizza', tags: ['delicious', 'best meal of the year','carb-free']},
  { name: 'rice cakes', tags: ['flavor-free','carb-free']}
]

So far I have tried the following. It seems to work only if there is only one value in foods.tags and that's a problem since most of the time foods.tags will have several items.

result= foods.filter(obj => { 
return (
[...obj.tags].some(item => tagsValues.includes(item))
)})
about 4 years ago · Juan Pablo Isaza
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!