sovsem-nub,
<script>
var arrObjects = [{
v: 8
}, {
v: 30
}, {
v: 3
}, {
v: 5
}];
function compare(field, order) {
order = order < 0 ? 1 : -1
return function(a, b) {
a = a[field];
b = b[field];
if (a < b) return order;
if (a > b) return -order;
return 0
}
};
var field = 'v',
order;
arrObjects = arrObjects.sort(compare(field, order));
document.write(JSON.stringify(arrObjects, "", 4));
document.write('<br>')
order = -1;
arrObjects = arrObjects.sort(compare(field, order));
document.write(JSON.stringify(arrObjects, "", 4));
</script>