Skip to content

pickBy

js
_.pickBy(object, [predicate=_.identity])

创建一个由 object 属性组成的对象,predicate 返回真值。使用两个参数调用谓词:(value, key)。

¥Creates an object composed of the object properties predicate returns truthy for. The predicate is invoked with two arguments: (value, key).

新增于

¥Since

4.0.0

参数

¥Arguments

  1. object (对象):源对象。

    ¥object (Object): The source object.

  2. [predicate=_.identity] (函数):每个属性调用的函数。

    ¥[predicate=_.identity] (Function): The function invoked per property.

返回

¥Returns

(对象):返回新对象。

¥(Object): Returns the new object.

示例

¥Example

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

_.pickBy(object, _.isNumber);
// => { 'a': 1, 'c': 3 }

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