utils
Version:
Fast, generic JavaScript/node.js utility functions.
28 lines (25 loc) • 603 B
JavaScript
;
/**
* Loop over each item in an array and call the given function on every element.
*
* ```js
* each(['a', 'b', 'c'], function (ele) {
* return ele + ele;
* });
* //=> ['aa', 'bb', 'cc']
*
* each(['a', 'b', 'c'], function (ele, i) {
* return i + ele;
* });
* //=> ['0a', '1b', '2c']
* ```
*
* @name .each
* @alias .forEach
* @param {Array} `array`
* @param {Function} `fn`
* @param {Object} `thisArg` Optionally pass a `thisArg` to be used as the context in which to call the function.
* @return {Array}
* @api public
*/
module.exports = require('array-each');