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

106
Views
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
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!