Socket
Socket
Sign inDemoInstall

array-iterate

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-iterate

forEach with the possibility to change the next position


Version published
Weekly downloads
445K
decreased by-3.64%
Maintainers
1
Weekly downloads
 
Created
Source

array-iterate

Build Coverage Downloads Size

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

Install

npm:

npm install array-iterate

Use

var iterate = require('array-iterate')

var isFirst = true
var context = {hello: 'world'}

iterate([1, 2, 3, 4], callback, context)

function callback(value, index, values) {
  console.log(this, value, index, values)

  if (isFirst && index + 1 === values.length) {
    isFirst = false
    return 0
  }
}

Yields:

{hello: 'world'}, 1, 0, [1, 2, 3, 4]
{hello: 'world'}, 2, 1, [1, 2, 3, 4]
{hello: 'world'}, 3, 2, [1, 2, 3, 4]
{hello: 'world'}, 4, 3, [1, 2, 3, 4]
{hello: 'world'}, 1, 0, [1, 2, 3, 4]
{hello: 'world'}, 2, 1, [1, 2, 3, 4]
{hello: 'world'}, 3, 2, [1, 2, 3, 4]
{hello: 'world'}, 4, 3, [1, 2, 3, 4]

API

iterate(values, callback[, context])

Works 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

Keywords

FAQs

Package last updated on 26 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc