Here is an example an object with an array I want to sort:
{
first: 'Zangief',
second: 'Cammy'
names: [
{name: 'Dee Jay'},
{name: 'Zangief'},
{name: 'Dhalsim'}
{name: 'Chun-Li'},
{name: 'Blanka'},
{name: 'Cammy'}
]
}
I want to have Zangief
fixed on the first place and Cammy
on the second place, and the rest is alphabetically ordered.
expected result:
[
{name: 'Zangief'},
{name: 'Cammy'},
{name: 'Blanka'}
{name: 'Chun-Li'},
{name: 'Dee Jay'},
{name: 'Dhalsim'},
]
I know this sorts the names alphabetically:
obj.names.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0));
and then I could find the two names and put them to the first two places, but is there a sorting function, what could do this while sorting?