Looking to organize a JavaScript Object structured as key:pair
, where the pair
consists of an array with 2 timestamp values. The goal is to arrange the elements so that those with the smallest numbers (earliest times) are shown first.
For instance, consider this object:
{"21_2":[1409158800,1409160000],"20_1":[1409148000,1409149200],"56_1":[1409149800,1409151600]}
In this scenario, the desired sorted object would be:
{"20_1":[1409148000,1409149200],"56_1":[1409149800,1409151600],"21_2":[1409158800,1409160000]}
To achieve this, the sort()
function will need to be utilized for the arrays. However, accessing these values within the object may be a challenge due to the non-integer nature of the object key
caused by the underscore.
While exploring potential solutions, I came across this resource: Sort Complex Array of Arrays by value within. Despite this, I have yet to successfully adapt it to my specific scenario. Any assistance on this matter would be highly appreciated.