阅读(3521) (8)

Lodash _.forIn

2021-09-23 09:28:23 更新

_.forIn(object, [iteratee=_.identity])

使用 iteratee 遍历对象的自身和继承的可枚举属性。 iteratee 会传入3个参数:(value, key, object)。 如果返回 false,iteratee 会提前退出遍历。

添加版本

0.3.0

参数

  1. object (Object): 要遍历的对象。
  2. [iteratee=_.identity] (Function): 每次迭代时调用的函数。

返回

(Object): 返回 object。

例子

function Foo() {  this.a = 1;  this.b = 2;} Foo.prototype.c = 3; _.forIn(new Foo, function(value, key) {  console.log(key);});
// => Logs 'a', 'b', then 'c' (无法保证遍历的顺序)。