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

109
Visualizações
Map function to select object properties based on an array of properties

I would like to find a solution that would allow me to use the map function to extract properties based on an array of properties. Ideally I would like a general solution so that I do not have to hard code the map function for each variation.

My use case: I am building an admin dashboard that will need to display 20+ tables - each with a different combination of columns. Using VueJS I have a table component to render the table but currently each table has the exact same columns being shown.

// every table shows these 4 columns
this.rows = this.menu.MenuItem.map(r => ({
   Id: r.Id,
   Name: r.Name,
   Description: r.Description,
   Category: r.Category
}))

Instead of the same columns for each table, I would like each table to be able to define which columns it would like to display. The same table component is used for each table, so I need a general solution to avoid writing a massive if-else block.

const MenuColumnMapping = [
    { menu: "Menu 1", columns: ["Id", "Name", "Description"] },
    { menu: "Menu 2", columns: ["Id", "Name", "Description", "Category" ] },
    { menu: "Menu 3", columns: ["Id", "Name", "Description", "Price", "Condition" ] },
    ...
]

How could I rewrite the map function to select the properties based on the array of columns for a given menu?

let cols = MenuColumnMapping
              .filter((m) => m.menu === this.menu.Name)
              .map((m) => m.columns)

// ex. cols = [ "Id", "Name", "Description", "Category" ]
this.rows = this.menu.MenuItem.map(r => ({
   
   // How can I select only the properties listed in cols

}))
about 4 years ago · Juan Pablo Isaza
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