sort object properties and JSON.stringify

后端 未结 22 2336
南方客
南方客 2020-11-28 05:44

My application has a large array of objects, which I stringify and save them to the disk. Unfortunately, when the objects in the array are manipulated, and sometimes replac

22条回答
  •  一个人的身影
    2020-11-28 06:28

    You can sort object by property name in EcmaScript 2015

    function sortObjectByPropertyName(obj) {
        return Object.keys(obj).sort().reduce((c, d) => (c[d] = obj[d], c), {});
    }
    

提交回复
热议问题