How can I remove entries such as this from an array
- _id = 0
- _id = ""
- _id = undefined
- _id = null
and then sort and limit the output to only 7 items with the highest costs?
MyArray
[
{_id : "" , M : "4", S : "2", Costs: "6"},
{_id : "0", M : "1", S : "0", Costs: "1"},
{_id : "1", M : "1", S : "0", Costs: "1"},
{_id : "2", M : "1", S : "0", Costs: "1"},
{_id : "3", M : "0", S : "3", Costs: "3"},
{_id : "4", M : "1", S : "0", Costs: "1"},
{_id : "5", M : "1", S : "0", Costs: "5"},
{_id : "6", M : "1", S : "0", Costs: "2"},
{_id : "7", M : "1", S : "0", Costs: "5"},
{_id : "8", M : "1", S : "0", Costs: "1"},
{_id : "9", M : "1", S : "0", Costs: "10"}
]
DESIRED OUTPUT
[
{_id : "9", M : "1", S : "0", Costs: "10"},
{_id : "7", M : "1", S : "0", Costs: "5"},
{_id : "5", M : "1", S : "0", Costs: "5"},
{_id : "3", M : "0", S : "3", Costs: "3"},
{_id : "6", M : "1", S : "0", Costs: "2"},
{_id : "1", M : "1", S : "0", Costs: "1"},
{_id : "2", M : "1", S : "0", Costs: "1"}
]