Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var arrayEach = require('../internal/arrayEach'),
2
baseEach = require('../internal/baseEach'),
3
createForEach = require('../internal/createForEach');
4
5
/**
6
* Iterates over elements of `collection` invoking `iteratee` for each element.
7
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
8
* (value, index|key, collection). Iteratee functions may exit iteration early
9
* 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 `_.forIn` or `_.forOwn`
13
* may be used for object iteration.
14
*
15
* @static
16
* @memberOf _
17
* @alias each
18
* @category Collection
19
* @param {Array|Object|string} collection The collection to iterate over.
20
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
21
* @param {*} [thisArg] The `this` binding of `iteratee`.
22
* @returns {Array|Object|string} Returns `collection`.
23
* @example
24
*
25
* _([1, 2]).forEach(function(n) {
26
* console.log(n);
27
* }).value();
28
* // => logs each value from left to right and returns the array
29
*
30
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
31
* console.log(n, key);
32
* });
33
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
34
*/
35
var forEach = createForEach(arrayEach, baseEach);
36
37
module.exports = forEach;
38
39