I need to be able to rename obj keys but keep them in the same order, with my code I am able to rename the key but it's inserted after the last key :
const program = {
"Day 1": {
exercise: {
exerciseType: ["you have no exercises", "please add"],
},
},
"Day 2": {
exercise: {
exerciseType: ["push-ups", "crunches"],
},
},
}
Object.defineProperty(program, 'fire',
Object.getOwnPropertyDescriptor(program, 'Day 1'));
delete program['Day 1'];
console.log(program)
/* {
Day 2: {
exercise: { ... }
},
fire: {
exercise: { ... }
}
}
*/
https://jsfiddle.net/p4waqn26/1/
I know this question was asked before, but the solutions I found didn't work for me, maybe because my keys are in quotes.