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
Extending AJP's answer, to handle arrays:
function sort(myObj) { var sortedObj = {}; Object.keys(myObj).sort().forEach(key => { sortedObj[key] = _.isPlainObject(myObj[key]) ? sort(myObj[key]) : _.isArray(myObj[key])? myObj[key].map(sort) : myObj[key] }) return sortedObj; }