eachr

Give eachr an array or object, and the iterator, in return eachr will give the iterator the value and key of each item, and will stop if the iterator returned false.

npm install eachr
419 downloads in the last day
2 122 downloads in the last week
9 155 downloads in the last month

Eachr Build Status

Give eachr an array or object, and the iterator, in return eachr will give the iterator the value and key of each item, and will stop if the iterator returned false.

Install

Backend

  1. Install Node.js
  2. npm install --save eachr

Frontend

  1. See Browserify

Usage

// Prepare
var each = require(".");
var arr = ["first", "second", "third"];
var obj = {a:"first", b:"second", c:"third"};
var iterator = function(value,key){
    console.log({value:value, key:key});
    if ( value === "second" ) {
        console.log("break");
        return false;
    }
};

// Cycle Array
each(arr, iterator);
// {"value":"first",  "key":0}
// {"value":"second", "key":1}
// break

// Cycle Object
each(obj, iterator);
// {"value":"first",  "key":"a"}
// {"value":"second", "key":"b"}
// break

History

You can discover the history inside the History.md file

License

Licensed under the incredibly permissive MIT License
Copyright © 2013+ Bevry Pty Ltd
Copyright © 2011-2012 Benjamin Arthur Lupton

npm loves you