UNPKG

1.03 kBJavaScriptView Raw
1import baseFor from './_baseFor';
2import baseIteratee from './_baseIteratee';
3import keysIn from './keysIn';
4
5/**
6 * Iterates over own and inherited enumerable string keyed properties of an
7 * object invoking `iteratee` for each property. The iteratee is invoked with
8 * three arguments: (value, key, object). Iteratee functions may exit iteration
9 * early by explicitly returning `false`.
10 *
11 * @static
12 * @memberOf _
13 * @since 0.3.0
14 * @category Object
15 * @param {Object} object The object to iterate over.
16 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
17 * @returns {Object} Returns `object`.
18 * @example
19 *
20 * function Foo() {
21 * this.a = 1;
22 * this.b = 2;
23 * }
24 *
25 * Foo.prototype.c = 3;
26 *
27 * _.forIn(new Foo, function(value, key) {
28 * console.log(key);
29 * });
30 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
31 */
32function forIn(object, iteratee) {
33 return object == null
34 ? object
35 : baseFor(object, baseIteratee(iteratee), keysIn);
36}
37
38export default forIn;