Lodash教程

Lodash invert method

语法

_.invert(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.

参数

object (Object) − The object to invert.

输出

(Object) − Returns the new inverted object.

实例

var _ = require('lodash');
var object = { 'a': 1, 'b': 2, 'c': 1 }; 
var result = _.invert(object);
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

{ '1': 'c', '2': 'b' }
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4