util-each

Iterate over an object, array or string

Usage no npm install needed!

<script type="module">
  import utilEach from 'https://cdn.skypack.dev/util-each';
</script>

README

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