@ndhoule/each

2020-01-13

@ndhoule/each

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

ci">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 iteratorfunction for each element in the collection, passing to the iterator three arguments: (value, index, collection).

The iteratorfunction 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.

以上是 @ndhoule/each 的使用教程帮助文档。


上一篇:@ndhoule/extend
下一篇:@ndhoule/defaults
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章
暂无相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部