I have an array like this:
user:[
{ name: "A", mobile: "123", status: "active"},
{ name: "B", mobile: "123", status: "active"},
{ name: "C", mobile: "123", status: "active"},
{ name: "D", mobile: "123", status: "active"},
{ name: "E", mobile: "123", status: "inactive"},
{ name: "F", mobile: "123", status: "inactive"},
];
Right now my code displays 4 records with "active" users first and "inactive" users at last
user.sort((a, b) =>a.status_id.localeCompare(b.status_id)).slice(0,4).map((d))
OUTPUT:
active
active
active
active
But what I want to display is - first half should be "active" and second half should be "inactive" and if there is no "inactive" user, then all should display "active" users
Displaying 4 records
active
active
inactive
inactive
How can I do this?