Converts an object to an array of single-key objects, sorted by key.
Each entry becomes its own object with one key-value pair, useful for serialization formats that need objects instead of tuples.
The input object type
Optional
The object to convert
Optional function to transform values during sorting
Array of objects, each with a single key-value pair, sorted by key
const sorted = toSortedObjectArray({ z: 3, a: 1, m: 2 });// [{ a: 1 }, { m: 2 }, { z: 3 }] Copy
const sorted = toSortedObjectArray({ z: 3, a: 1, m: 2 });// [{ a: 1 }, { m: 2 }, { z: 3 }]
Converts an object to an array of single-key objects, sorted by key.
Each entry becomes its own object with one key-value pair, useful for serialization formats that need objects instead of tuples.