1 var arrayEach = require('./_arrayEach'),
2 baseEach = require('./_baseEach'),
3 castFunction = require('./_castFunction'),
4 isArray = require('./isArray');
7 * Iterates over elements of `collection` and invokes `iteratee` for each element.
8 * The iteratee is invoked with three arguments: (value, index|key, collection).
9 * Iteratee functions may exit iteration early by explicitly returning `false`.
11 * **Note:** As with other "Collections" methods, objects with a "length"
12 * property are iterated like arrays. To avoid this behavior use `_.forIn`
13 * or `_.forOwn` for object iteration.
19 * @category Collection
20 * @param {Array|Object} collection The collection to iterate over.
21 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
22 * @returns {Array|Object} Returns `collection`.
26 * _.forEach([1, 2], function(value) {
29 * // => Logs `1` then `2`.
31 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
34 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
36 function forEach(collection, iteratee) {
37 var func = isArray(collection) ? arrayEach : baseEach;
38 return func(collection, castFunction(iteratee));
41 module.exports = forEach;