I have an object like this:
const obj = {
a: {a: 0, b: 0},
b: {a: 1, b: 1},
c: {a: 2, b: 2},
d: {a: 3, b: 3},
};
I basically just want to move one key and its value to the first position of the object, like this:
const obj = {
c: {a: 2, b: 2},
a: {a: 0, b: 0},
b: {a: 1, b: 1},
d: {a: 3, b: 3},
};
I was thinking something like this:
const { [c]: firstKeyValue, ...rest } = obj;
const sortedObj {
[c]: firstKeyValue,
...rest
};
Any other ideas?