@ndhoule/each

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

each

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.

HomePage

https://github.com/ndhoule/each

Repository

https://github.com/ndhoule/each.git


上一篇:@ndhoule/extend
下一篇:@ndhoule/defaults

相关推荐

  • @ndhoule/rest

    Produce a new array composed of all but the first element of the input collection. rest CIcibadgec...

    6 个月前
  • @ndhoule/pick

    Create a shallow copy of an input object that contains only the specified properties. pick CIcibad...

    7 个月前
  • @ndhoule/map

    Apply a function to a each element of a collection and return a new array of results. map CIcibadg...

    7 个月前
  • @ndhoule/keys

    Create an array of the owned/enumerable keys of an input object. keys CIcibadgecilink Create an a...

    7 个月前
  • @ndhoule/includes

    Determine whether or not a value is contained by a given collection. includes CIcibadgecilink Det...

    7 个月前
  • @ndhoule/foldl

    Apply a function to each value in a collection, accumulating the results into a single return value....

    7 个月前
  • @ndhoule/extend

    Extend an object with the properties of another. extend CIcibadgecilink Extend an object with the...

    7 个月前
  • @ndhoule/every

    Check if a function returns true for all values in a . every CIcibadgecilink Check if a functio...

    6 个月前
  • @ndhoule/drop

    Produce a new array composed of all but the first n elements of an input collection. drop CIcibadg...

    6 个月前
  • @ndhoule/defaults

    Copies owned, enumerable properties from a source object(s) to a target object when the value of tha...

    7 个月前

官方社区

扫码加入 JavaScript 社区