I have an object with a sub-object with ids. I would like to order the subobject by a specific property but without loosing the id references.
I've tried ordering individually the subobject "options" by position using lodash and different vanilla js solutions I've found and reasigning it to the main object, but I loose the ids because in all cases it returns an array and I can't find a way to keep the same id structure.
Object example:
{
name: 'User name',
options: {
'234aafg': {
name: 'bar',
position: 2
},
'543al22': {
name: 'foo',
position: 0
},
'437uaz2': {
name: 'baz',
position: 1
},
}
}
Expected Result:
{
name: 'User name',
options: {
'543al22': {
name: 'foo',
position: 0
},
'437uaz2': {
name: 'baz',
position: 1
},
'234aafg': {
name: 'bar',
position: 2
}
}
}