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

118
Visualizações
Issue when trying to sort array?
        // const first = data.groups_with_selected[7];
        // const second = data.groups_with_selected[20];
        // data.groups_with_selected.splice(2, 0, first, second);
        // data.groups_with_selected.splice(9, 1)
        // data.groups_with_selected.splice(21, 1)

But Issue with the above code is that, I am able to get the updated sorted console value in the console. But filters wise it's not updating.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the solution for this problem is by grouping the array first, then use flat() to flatten/restore it so it have the same level:

const orderMap = ['third', 'second', 'first'];

const array = [{name: 'first'}, {name: 'second'}, {name: 'third'}, {name: 'second'}];

const sorted = orderMap.reduce((prev, curr, index) => {
prev[index] = array.filter(item => item.name === curr)
return prev
}, []).flat()

console.log(sorted)

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