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

342
Views
Ordenar una matriz con objetos, Javascript

¿Cómo ordenar esta matriz por valor time2 ? (de mayor a menor) Las matrices con índices [0] y [1] en la matriz arr deben intercambiarse (arr[0] , arr[1]). Gracias

 var arr = [ [ 123, { "name": "Tanya", "date": "20.1.1976", "time": { "time1": 4665435666, "time2": 1655266247 }, "photo": "1", "sex": "1" } ], [ 145, { "name": "Andrey", "date": "10.4.1986", "time": { "time1": 4665442222, "time2": 2655245555 }, "photo": "1", "sex": "0" } ] ]; alert (arr[0]); alert (arr[1]);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Suponiendo que su elemento de matriz siempre tiene 2 subelementos. así es como puede ordenar en orden desc

 var arr = [ [ 123, { "name": "Tanya", "date": "20.1.1976", "time": { "time1": 4665435666, "time2": 1655266247 }, "photo": "1", "sex": "1" } ], [ 145, { "name": "Andrey", "date": "10.4.1986", "time": { "time1": 4665442222, "time2": 2655245555 }, "photo": "1", "sex": "0" } ] ]; const sortedArr = arr.sort((a, b) => { return (a[1].time.time2 < b[1].time.time2) ? 1 : -1 }); console.log(sortedArr);

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!