I have Array of object data which i want to sort objects of the Array by the specific key that is favourite
. In the Array of fruits. it has some object of the fruits. I just want to sort according to the favourite
key. if the key favourite:true
inside object then this object will go to the top and if favourite:true
is found in the more than one object,then always set top of first object which found the favourite:true
key.
Input data:
[
{
id: 1,
title: 'Banana',
},
{
id: 2,
title: 'Mango',
favourite:true
},
{
id:3,
title: 'Apple',
},
]
expected Output data:
[
{
id: 2,
title: 'Mango',
favourite:true
},
{
id: 1,
title: 'Banana',
},
{
id:3,
title: 'Apple',
}
]