Node.js lodash forEach() iterate over elements of collection

Introduction

Iterates over elements of collection invoking iteratee for each element.

The iteratee is bound to this-Arg and invoked with three arguments:

(value, index|key, collection). 

Iteratee functions may exit iteration early by explicitly returning false.

var lodash = require('lodash');
lodash([1,2]).forEach(function(n){
  console.log(n);//from w  w w.ja v  a 2s  .  c  o m
}).value();
//this will give 
//1
//2

lodash.forEach({'a':1, 'b': 2}, function(n, key) {
  console.log(n, key);
});



PreviousNext

Related