@ndhoule/each

2.0.1 • Public • Published

each CI

Iterate over a collection, invoking a function for each element in the collection.

Installation

$ 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.

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']
//=> undefined

each(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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    214,695
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.1
    214,695
  • 2.0.0
    0
  • 1.0.3
    76
  • 1.0.2
    0

Package Sidebar

Install

npm i @ndhoule/each

Weekly Downloads

214,771

Version

2.0.1

License

MIT

Last publish

Collaborators

  • ndhoule