Open this example in the interactive library
Source code
type Row = { id: number; name: string; rank: number | null };
const rows: Row[] = [
{ id: 2, name: "Beta", rank: null },
{ id: 1, name: "Alpha", rank: 3 },
];
console.log(
Map.groupBy(rows, (row) => (row.rank === null ? "unranked" : "ranked")).get(
"ranked",
),
);
Sample output
[ { id: 1, name: 'Alpha', rank: 3 } ]