I have an array like this
var array = [{
order: 3,
sub - array: [{
order: 2
},{
order: 1
}]
},{
order: 2,
sub - array
Use Array.prototype.sort
and call it on array
and subsequently on each element of array
with an appropriate compare function.
Something like this should work:
array.sort(function (e1, e2) {
return (e1.order - e2.order);
});
array.forEach(function(e) {
e["sub-array"].sort(function (e1, e2) {
return (e1.order - e2.order);
});
});