1function sortObjectByKeys(o) {
2 return Object.keys(o).sort().reduce((r, k) => (r[k] = o[k], r), {});
3}
4var unsorted = {"c":"crane","b":"boy","a":"ant"};
5var sorted=sortObjectByKeys(unsorted); //{a: "ant", b: "boy", c: "crane"}
1itemsArray.sort(function(a, b){
2 return sortingArr.indexOf(a) - sortingArr.indexOf(b);
3});