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

239
Views
JS : arrow function or array map?

Based on this code, I would like to use an arrow function, I am not really used to.. What's the best way to wrote it ?

I would like to keep the same sort order. Since "selectedHeader" is like you can guess, a column variable based on a vue js v-select.

const headers = 
  [ { text: 'City',                  value: 'city'   } 
  , { text: 'Zip code',              value: 'zip'    } 
  , { text: 'Country',               value: 'country'} 
  , { text: 'Number of Inhabitants', value: 'inhabitants' } 
  ];

const selectedHeaders = 
  [ { text: 'City',     value: 'city' } 
  , { text: 'Zip code', value: 'zip'  } 
  ];
  
let tab = [];

for (i = 0; i < headers.length; i++) {
  pos = selectedHeaders.map(function(e) {
    return e.value;
  }).indexOf(headers[i].value);
  if (pos > -1) {
    tab.push(headers[i]);
  }
}

console.log(tab);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to use arrow functions, you can use filter

    const headers = [ { "text": "City", "value": "city" }, { "text": "Zip code", "value": "zip" },{ "text": "Country", "value": "country" },{ "text": "Number of Inhabitants", "value": "inhabitants" }];
    const selectedHeaders = [ { "text": "City", "value": "city" }, { "text": "Zip code", "value": "zip" }];
    let tab =[];
    
    const selectedValues = selectedHeaders.map(header => header.value);
    tab = headers.filter(header => selectedValues.includes(header.value));
    console.log(tab);
about 4 years ago · Juan Pablo Isaza Report
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!