1.0.1 • Published 10 years ago

util-each v1.0.1

Weekly downloads
12
License
MIT
Repository
github
Last release
10 years ago

Each

NPM version Build status Test coverage Gittip

Iterate over an object, array or string.

Installation

npm install util-each --save

Usage

var each = require('util-each');

// Iterate over objects.
each({
  a: 0,
  b: 1,
  c: 2
}, function (value, key, obj) {
  console.log([value, key, obj]);
  //=> [0, 'a', { a: 0, b: 1, c: 2 }]
  //=> [1, 'b', { a: 0, b: 1, c: 2 }]
  //=> [2, 'c', { a: 0, b: 1, c: 2 }]
});

// Iterate over arrays.
each(['a', 'b', 'c'], function (value, key, obj) {
  console.log([value, key, obj]);
  //=> ['a', 0, ['a', 'b', 'c']]
  //=> ['b', 1, ['a', 'b', 'c']]
  //=> ['c', 2, ['a', 'b', 'c']]
});

// Iterate over strings.
each('abc', function (value, key, obj) {
  console.log([value, key, obj]);
  //=> ['a', 0, 'abc']
  //=> ['b', 1, 'abc']
  //=> ['c', 2, 'abc']
});

License

MIT