Dev Helpers
← Back

Find the earliest sorted match

Find the earliest sorted match using TypeScript.

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(rows.toSorted((a, b) => a.id - b.id).find((r) => r.rank !== null));

Sample output

{ id: 1, name: 'Alpha', rank: 3 }