1 var arrayEach = require('./_arrayEach'),
2 baseEach = require('./_baseEach'),
3 isArray = require('./isArray'),
4 toFunction = require('./_toFunction');
7 * Iterates over elements of `collection` invoking `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" property
12 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
13 * for object iteration.
18 * @category Collection
19 * @param {Array|Object} collection The collection to iterate over.
20 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
21 * @returns {Array|Object} Returns `collection`.
24 * _([1, 2]).forEach(function(value) {
27 * // => logs `1` then `2`
29 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
32 * // => logs 'a' then 'b' (iteration order is not guaranteed)
34 function forEach(collection, iteratee) {
35 return (typeof iteratee == 'function' && isArray(collection))
36 ? arrayEach(collection, iteratee)
37 : baseEach(collection, toFunction(iteratee));
40 module.exports = forEach;