JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 905083
  • Score
    100M100P100Q184721F
  • License MIT

forEach with the possibility to change the next position

Package Exports

  • array-iterate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-iterate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

array-iterate Build Status Coverage Status

Array#forEach() with the possibility to change the next position.

Installation

npm:

npm install array-iterate

Usage

var iterate = require('array-iterate');
var isFirst = true;
var context = 'iterate';

iterate([1, 2, 3, 4], function (value, index, values) {
  console.log(this, value, index, values)

  if (isFirst && index + 1 === values.length) {
    isFirst = false;
    return 0;
  }
}, context);
/**
 * [String: 'iterate'], 1, 0, [ 1, 2, 3, 4 ]
 * [String: 'iterate'], 2, 1, [ 1, 2, 3, 4 ]
 * [String: 'iterate'], 3, 2, [ 1, 2, 3, 4 ]
 * [String: 'iterate'], 4, 3, [ 1, 2, 3, 4 ]
 * [String: 'iterate'], 1, 0, [ 1, 2, 3, 4 ]
 * [String: 'iterate'], 2, 1, [ 1, 2, 3, 4 ]
 * [String: 'iterate'], 3, 2, [ 1, 2, 3, 4 ]
 * [String: 'iterate'], 4, 3, [ 1, 2, 3, 4 ]
 */

API

iterate(values, callback[, context])

Functions just like Array#forEach(), but when callback returns a number, iterates over the item at number next.

Parameters
  • values (Array-like thing) — Values to iterate over
  • callback (Function) — Callback given to iterate.
  • context (*, optional) — Context object to use when invoking callback.

function callback(value, index, values)

Callback given to iterate.

Parameters
  • value (*) — Current iteration;
  • index (number) — Position of value in values;
  • values (Array-like thing) — Currently iterated over.
Context

context, when given to iterate.

Returns

number (optional) — Position to go to next.

License

MIT © Titus Wormer