let jsonArray = [{ "name": "Alice", "age": 25 }, { "name": "Bob", "age": 30 }, { "name": "Charlie", "age": 20 }];
jsonArray.sort(function(a, b) {
return a.age - b.age;
});
console.log(jsonArray);
const _ = require('lodash');
let jsonArray = [{ "name": "Alice", "age": 25 }, { "name": "Bob", "age": 30 }, { "name": "Charlie", "age": 20 }];
let sortedArray = _.sortBy(jsonArray, 'age');
console.log(sortedArray);
let jsonArray = [{ "name": "Alice", "age": 25 }, { "name": "Bob", "age": 30 }, { "name": "Charlie", "age": 20 }];
jsonArray.sort(function(a, b) {
return JSON.stringify(a) > JSON.stringify(b) ? 1 : -1;
});
console.log(jsonArray);