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

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

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 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