I implemented sort in alphabetical order and wanted rearrange the objects (move all status red object to the bottom of the array. How I can move all status red data to end of the array in from my onLoad function?
// sample data
const data = [
{
status: "green",
name: "alex"
},
{
status: "red",
name: "ken"
},
{
status: "red",
name: "roy"
},
{
status: "green",
name: "boy"
}
]
users: User[];
// get list
onLoad() {
this.service.getList$
.pipe(takeUntil(this._unsubscribeAll))
.subscribe((users: User[]) => {
this.users = users;
.sort((a, b) => 0 - (a.name > b.name ? -1 : 1));
});
}