Lodash - toPairs 方法

语法

_.toPairs(object)

为 object 创建一个可枚举的字符串键值对数组,可供 _.fromPairs 使用。如果 object 是映射或集合,则返回其条目。

参数

  • object (Object) − 要查询的对象。

输出

  • (Array) − 返回键值对。

示例

var _ = require('lodash');
 
function Foo() {
   this.a = 1;
   this.b = 2;
}
 
Foo.prototype.c = 3;

console.log(_.toPairs(new Foo));

将上述程序保存在tester.js中。运行以下命令执行该程序。

命令

\>node tester.js

输出

[ [ 'a', 1 ], [ 'b', 2 ] ]

lodash_object.html