Skip to content

Function: invert()

ts
function invert(object): Record<string, string>;

Swaps the keys and values of a flat object. 交换扁平对象的键和值。

Parameters

ParameterTypeDescription
objectRecord<string, string | number | symbol>The source object / 源对象

Returns

Record<string, string>

A new object with swapped keys and values / 键值交换后的新对象

Example

ts
invert({ a: 'x', b: 'y' })
// => { x: 'a', y: 'b' }

Since

1.2.0

Released under the MIT License.