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);
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: sql json数组取值的方法是什么