Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ndhoule/each
Iterate over a collection, invoking a function for each element.
https://github.com/ndhoule/each
Last synced: 13 days ago
JSON representation
Iterate over a collection, invoking a function for each element.
- Host: GitHub
- URL: https://github.com/ndhoule/each
- Owner: ndhoule
- License: mit
- Created: 2015-02-25T20:08:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-02T19:58:50.000Z (over 8 years ago)
- Last Synced: 2024-10-07T08:18:48.202Z (about 1 month ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.md
Awesome Lists containing this project
README
# each [![CI][ci-badge]][ci-link]
Iterate over a collection, invoking a function for each element in the collection.
## Installation
```sh
$ component install ndhoule/each
$ npm install @ndhoule/each
```## API
### `each(iterator : Function, collection : Array|Object|string) => undefined`
Iterate over an input collection, invoking an `iterator` function for each element in the collection, passing to the iterator three arguments: `(value, index, collection)`.
The `iterator` function can end iteration early by returning `false`.
```javascript
var log = console.log.bind(console);each(log, ['a', 'b', 'c']);
//-> 'a', 0, ['a', 'b', 'c']
//-> 'b', 1, ['a', 'b', 'c']
//-> 'c', 2, ['a', 'b', 'c']
//=> undefinedeach(log, 'tim');
//-> 't', 2, 'tim'
//-> 'i', 1, 'tim'
//-> 'm', 0, 'tim'
//=> undefined// Note: Iteration order not guaranteed across environments
each(log, { name: 'tim', occupation: 'enchanter' });
//-> 'tim', 'name', { name: 'tim', occupation: 'enchanter' }
//-> 'enchanter', 'occupation', { name: 'tim', occupation: 'enchanter' }
//=> undefined
```## License
Released under the [MIT license](LICENSE.md).
[ci-link]: https://travis-ci.org/ndhoule/each
[ci-badge]: https://travis-ci.org/ndhoule/each.svg?branch=master