e7bde6dee8b9155dfba2d102a82b11c5ae88ba12
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / forEach.js
1 var arrayEach = require('./_arrayEach'),
2     baseEach = require('./_baseEach'),
3     isArray = require('./isArray'),
4     toFunction = require('./_toFunction');
5
6 /**
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`.
10  *
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.
14  *
15  * @static
16  * @memberOf _
17  * @alias each
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`.
22  * @example
23  *
24  * _([1, 2]).forEach(function(value) {
25  *   console.log(value);
26  * });
27  * // => logs `1` then `2`
28  *
29  * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
30  *   console.log(key);
31  * });
32  * // => logs 'a' then 'b' (iteration order is not guaranteed)
33  */
34 function forEach(collection, iteratee) {
35   return (typeof iteratee == 'function' && isArray(collection))
36     ? arrayEach(collection, iteratee)
37     : baseEach(collection, toFunction(iteratee));
38 }
39
40 module.exports = forEach;