Skip to content

invert

js
_.invert(object)

创建一个由 object 的反转键和值组成的对象。如果 object 包含重复值,则后续值将覆盖先前值的属性分配。

¥Creates an object composed of the inverted keys and values of object. If object contains duplicate values, subsequent values overwrite property assignments of previous values.

新增于

¥Since

0.7.0

参数

¥Arguments

  1. object (对象):要修改的对象。

    ¥object (Object): The object to invert.

返回

¥Returns

(对象):返回新的反转对象。

¥(Object): Returns the new inverted object.

示例

¥Example

js
var object = { 'a': 1, 'b': 2, 'c': 1 };

_.invert(object);
// => { '1': 'c', '2': 'b' }

Lodash v4.17 中文网 - 粤ICP备13048890号