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

179
Views
¿Cómo ordenar una matriz según el segundo valor con javascript?

tengo una matriz:

 [ [0, 'Please select a Customer'], [2072, 'S-Customer'], [834, '01-Customer'], [709, 'C-Customer'], [4217, 'Test'], [2074, 'A-Customer'] ]

pero, ¿cómo puedo ordenarlo numérica y alfabéticamente y aún tener la misma identificación que es el primer valor? Sería así:

obs: el primer valor no debe cambiarse.

 [ [0, 'Please select a Customer'], [834, '01-Customer'], [2074, 'A-Customer'], [709, 'C-Customer'], [2072, 'S-Customer'], [4217, 'Test'] ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede mantener la primera matriz en su lugar mirando el índice 0 y ordenar el resto por el valor del índice 1

 const array = [[0, 'Please select a Customer'], [2072, 'S-Customer'], [834, '01-Customer'], [709, 'C-Customer'], [4217, 'Test'], [2074, 'A-Customer']]; array.sort((a, b) => !b[0] - !a[0] || a[1].localeCompare(b[1])); console.log(array);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

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!