invert
@guoba-ai/utils / object / invert
Function: invert()
function invert(obj): Record<string, string>;Defined in: object.ts:228
Swap the keys and values of an object.
Parameters
obj
Record<string, string | number | symbol>
The object to invert
Returns
Record<string, string>
A new object with keys and values swapped
Example
invert({ a: '1', b: '2' }) // { '1': 'a', '2': 'b' }
invert({ x: 1, y: 2 }) // { '1': 'x', '2': 'y' }
invert({ a: 'same', b: 'same' }) // { same: 'b' }Warning
Values are stringified as object keys. If values collide, the later key wins.