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

121
Views
Sort array of objects based on object property that has special chars

I have an array of objects, like this:

array = [ {userId: 'Y-10'}, {userId: 'Y-1'}, {userId: 'Y-14'}, {userId: 'Y-24'} ];

I need to sort the array by the userId in order. The results should be in this order: 'Y-1','Y-10','Y-14','Y-24'

I tried using a sort like this array.sort((a,b) => ("" + a.userId).localeCompare(b.userId, undefined, {numeric: true}));

But this doesnt work. How can I sort my array to yield the results i'm seeking?

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!