📜  对象 js 的排序数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:14.450000             🧑  作者: Mango

代码示例6
function sortObjectByKeys(o) {
    return Object.keys(o).sort().reduce((r, k) => (r[k] = o[k], r), {});
}
var unsorted = {"c":"crane","b":"boy","a":"ant"};
var sorted=sortObjectByKeys(unsorted); //{a: "ant", b: "boy", c: "crane"}