Loop over each item in an array and call the given function on every element.
Install with npm
npm i array-each --savevar each = require('array-each'); var result = []; each(['a', 'b', 'c'], function (ele) { result.push(ele + ele); }); console.log(result); //=> ['aa', 'bb', 'cc']Return false to "break" early:
var result = []; each(['a', 'b', 'c'], function (ele) { if (ele === 'b') return false; result.push(ele + ele); }); console.log(result); //=> ['aa']Loop over each item in an array and call the given function on every element.
Params
array{Array}fn{Function}thisArg{Object}: Optionally pass athisArgto be used as the context in which to call the function.returns{Array}
Example
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']- arr-filter: Faster alternative to javascript's native filter method.
- arr-diff: Returns an array with only the unique values from the first array, by excluding all… more
- arr-map: Faster, node.js focused alternative to JavaScript's native array map.
- arr-flatten: Recursively flatten an array or arrays. This is the fastest implementation of array flatten.
- array-unique: Return an array free of duplicate values. Fastest ES5 implementation.
- array-intersection: Return an array with the unique values present in all given arrays using strict equality… more
Install dev dependencies:
npm i -d && npm testPull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on April 28, 2015.