listify
@guoba-ai/utils / object / listify
Function: listify()
function listify<T, U>(obj, fn): U[];Defined in: object.ts:335
Convert an object to an array by mapping each key-value pair.
Parameters
obj
T
The source object
fn
(key, value) => U
Function that receives each key and value, returns the array element
Returns
U[]
An array of mapped values
Example
listify({ a: 1, b: 2 }, (key, value) => `${key}=${value}`)
// ['a=1', 'b=2']
listify({ x: 10, y: 20 }, (_key, value) => value)
// [10, 20]
listify({}, (key, value) => [key, value]) // []