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

340
Views
Sorting an array with objects, Javascript

How to sort this array by value time2? (from largest to smallest) Arrays with indexes [0] and [1] in array arr must be exchanged (arr[0] , arr[1]). Thanks

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

Assuming your array item has always 2 sub items. here is how you can sort in desc order

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!