You could read it here on MDN
Array has a sort function :
arr.sort([compareFunction])
Assuming you have :
var myArr=[{
"H": 5,
"Date": {
Y: 2015,
M: 3,
D: 01
}
},{
"H": 5,
"Date": {
Y: 2015,
M: 3,
D: 21
}
},{
"H": 5,
"Date": {
Y: 2015,
M: 3,
D: 11
}
}];
You can sort it with a functionj that takes 2 argument - each of them is an object to compare :
for example
If compareFunction(a, b) is less than 0, sort a to a lower index than
b, i.e. a comes first.
So you can now create 2 dates to compare
myArr.sort(function (a,b){ return new Date(a.Date.Y,a.Date.M,a.Date.D,a.H,0,0) - new Date(b.Date.Y,b.Date.M,b.Date.D,b.H,0,0)})
you might want to notice that
new Date(1978,11,22) - new Date(1978,11,21)
will yield a number :
86400000
while
new Date(1978,11,22)
will yield another representation
Fri Dec 22 1978 00:00:00 GMT+0200 (Jerusalem Standard Time)
(depending on local environment)
http://jsbin.com/gusokamoye/3/edit