例如JSON数据:javascript
let json = [ { index: 2, name: "2" }, { index: 2, name: "2" }, { index: 1, name: "1" }, { index: 3, name: "3" } ]; json = json.sort((a, b) => { return a.index - b.index; }); console.log(json);
解释:按key为index的从小到大排序。java
输出:json