I have an array of objects and I want to sort them by the object ids.
I tried using
options.sort((a, b) => a.id.localeCompare(b.id));
but did not worked as expected because it is sorting even the 'all' object and I don't want this (the object with id='all' should be first in my array, after that should be the objects in ascending order). Below you can see the input and the output of my code
Input:
var items =
[{ 'Name':'All', 'id': 'all'
{ 'Name':'item1', 'id': '003' }
{ 'Name':'item2', 'id': '001' }
{ 'Name':'item3', 'id': '002' }];
Output:
var items =
[{ 'Name':'item2', 'id': '001' }
{ 'Name':'item3', 'id': '002' }
{ 'Name':'item1', 'id': '003' }
{ 'Name':'All', 'id': 'all'}];