例如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