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

150
Vistas
How can we compare objects by value stored inside two arrays of objects in JavaScript?

I have one array of objects containing the menu for my multi select dropdown

const menu = [
    {
        label: "test 1",
        value: "test1",
    },
    {
        label: "test 2",
        value: "test2",
    },
    // so on
]

I have another array of object that is storing selected multiple values from the menu:

const values = [
    {
        label: "test 1",
        value: "test1",
    }
    // It can contain more than one values since the dropdown is multiselect
]

Remember that menu array contains all the options that I am displaying in my dropdown. Now, what I want is to filter out the selected values from the dropdown. For this purpose, I will need to filter out info from menu array of objects and for that filtration, I will be using values array of objects so that the objects inside the two arrays can be compared and filter out from my menu array of objects.

I have tried numerous JS methods but nothing is working in my case. I cannot use includes method because it compares values by reference and not by value. This is the reason why my condition fails since JS considers both of the objects to be different (their address is different), although they have the same value.

Looking forward to a solution.

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

0

selectedValues = values.map(item => item.value)
menu.filter(item => selectedValues.includes(item.value))
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