Skip to content

A foreach that supports arrays and objects, provides the value and key/index, as well as break support on return false

License

Notifications You must be signed in to change notification settings

elegant-talk/foreach-elegant

Repository files navigation

foreach-elegant

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Slack community badge Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

A foreach that supports arrays and objects, provides the value and key/index, as well as break support on return false

Install

NPM

  • Install: npm install --save foreach-elegant
  • Module: require('foreach-elegant')

Browserify

  • Install: npm install --save foreach-elegant
  • Module: require('foreach-elegant')
  • CDN URL: //wzrd.in/bundle/[email protected]

Ender

  • Install: ender add foreach-elegant
  • Module: require('foreach-elegant')

This package is published with the following editions:

  • foreach-elegant aliases foreach-elegant/index.js which uses Editions to automatically select the correct edition for the consumers environment
  • foreach-elegant/source/index.js is Source + ESNext + Require + Flow Type Comments
  • foreach-elegant/es2015/index.js is Babel Compiled + ES2015 + Require

Older environments may need Babel's Polyfill or something similar.

Usage

var foreach = require('foreach-elegant')
function iterator (value, key, list) {
    console.log('received', key, '=', value, 'from', list)
    if ( key === 'b' || value === 'y' ) {
        console.log('ending iteration early')
        return false
    }
}

foreach({a:1, b:2, c:3}, iterator)
foreach(['x', 'y', 'z'], iterator)

foreach({a:1, c:3}, iterator)
foreach(['x', 'z'], iterator)

History

Discover the release history by heading on over to the HISTORY.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under:

About

A foreach that supports arrays and objects, provides the value and key/index, as well as break support on return false

Resources

License

Stars

Watchers

Forks

Packages

No packages published