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

117
Views
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 answers
Answer question

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