I have the following Object in JS:
var obj = {
elem_1: "el1",
elem_2: "el2",
elem_3: "el3",
exp_1: "ex1",
exp_2: "ex2",
exp_3: "ex3"
};
I am trying to reorder it so each elem_#
is followed by exp_#
.
I started the following code but not sure how I can achieve it:
obj.sort(function (index, data) {
return data.key.split('_')[1] == '1' ? 2 : data.key == '2' ? 1 : 0
});
How can I achieve what I am looking to do.