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

174
Vistas
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
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