企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## forIn + [link](./forIn "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L11006 "View in source.") + [npm](https://www.npmjs.com/package/lodash.forin "See the npm package.") ``` _.forIn(object, [iteratee=_.identity]) ``` 使用 `iteratee` 遍历对象的自身和继承的可枚举属性。 iteratee 会传入3个参数:(value, key, object)。 如果返回 false,iteratee 会提前退出遍历。 ### 参数 1. object (Object) 要遍历的对象 2. [iteratee=_.identity] (Function) 这个函数会处理每一个元素 ### 返回值 (Object) 返回对象 ### 示例 ``` function Foo() { this.a = 1; this.b = 2; } Foo.prototype.c = 3; _.forIn(new Foo, function(value, key) { console.log(key); }); // => 输出 'a', 'b', 然后 'c' (无法保证遍历的顺序) ```