I've got the following object which I'd like to sort by its priority fields.
{
    anchor_block: {
        label: 'Anker-Block',
        priority: 100,
        description: ...,
        fields: ...
    },
    categories_block: {
        label: 'Categories-Block',
        description: ...,
        fields: ...
    },
    contact_block: {
        label: 'Kontakt-Block',
        description: ...,
        fields: ...
    },
    employee_block: {
        label: 'Mitarbeiter-Block',
        priority: 90,
        description: ...,
        fields: ...
    }
}
I've tried to sort them with lodash:
_.orderBy(blocks, ['priority'], ['desc']);
But this solution removes the all the keys from my objects (because it returns an array) and it also puts the ones without a priority field on top:
[
    {
        label: 'Categories-Block',
        description: ...,
        fields: ...
    },
    {
        label: 'Kontakt-Block',
        description: ...,
        fields: ...
    },
    {
        label: 'Anker-Block',
        priority: 100,
        description: ...,
        fields: ...
    },
    {
        label: 'Mitarbeiter-Block',
        priority: 90,
        description: ...,
        fields: ...
    },
]
Does any one of you have an idea on how to solve this with lodash? I'd like to avoid iterating it myself, because I'm sure it's possible, I just don't get my head around it.
 
    