blob: 12afef4d34fee16154d67f742cbbe886ec203f4f [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/*!
2 * array-each <https://github.com/jonschlinkert/array-each>
3 *
4 * Copyright (c) 2015, 2017, Jon Schlinkert.
5 * Released under the MIT License.
6 */
7
8'use strict';
9
10/**
11 * Loop over each item in an array and call the given function on every element.
12 *
13 * ```js
14 * each(['a', 'b', 'c'], function(ele) {
15 * return ele + ele;
16 * });
17 * //=> ['aa', 'bb', 'cc']
18 *
19 * each(['a', 'b', 'c'], function(ele, i) {
20 * return i + ele;
21 * });
22 * //=> ['0a', '1b', '2c']
23 * ```
24 *
25 * @name each
26 * @alias forEach
27 * @param {Array} `array`
28 * @param {Function} `fn`
29 * @param {Object} `thisArg` (optional) pass a `thisArg` to be used as the context in which to call the function.
30 * @return {undefined}
31 * @api public
32 */
33
34module.exports = function each(arr, cb, thisArg) {
35 if (arr == null) return;
36
37 var len = arr.length;
38 var idx = -1;
39
40 while (++idx < len) {
41 var ele = arr[idx];
42 if (cb.call(thisArg, ele, idx, arr) === false) {
43 break;
44 }
45 }
46};