Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

0

selectedValues = values.map(item => item.value)
menu.filter(item => selectedValues.includes(item.value))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda