I have an array like this
var array = [{
order: 3,
sub - array: [{
order: 2
},{
order: 1
}]
},{
order: 2,
sub - array
var propertySort = function(a, b){
return a.order > b.order ? 1 : (a.order < b.order ? -1 : 0);
}
var reorder = function(arr){
var l = arr.length;
while (l--){
if (arr[l]['sub-array']){
reorder(arr[l]['sub-array']);
}
}
arr.sort(propertySort);
};
reorder(arr);
console.log(arr);
This should re-order the array for any number of nested levels.