Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break _.forEach in lodash?

I can't break _.forEach loop, help me to do that.

_.forEach(oIncludedFileMap, function (aIncludedFiles, sKey) {   if(aIncludedFiles == null){      break;   } }); 
like image 418
Mangesh Darekar Avatar asked Sep 13 '17 16:09

Mangesh Darekar


People also ask

How do you break out of Lodash forEach?

Javascript. Conclusion: Hence to break Lodash forEach loop we have to return false from the callback function.

Can you break out of forEach?

Officially, there is no proper way to break out of a forEach loop in javascript. Using the familiar break syntax will throw an error. If breaking the loop is something you really need, it would be best to consider using a traditional loop.

What is _ forEach in Javascript?

Syntax. _.forEach(collection, [iteratee=_.identity]) Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.


1 Answers

To finish lodash#forEach method use return false; statement:

_.forEach(oIncludedFileMap, function(aIncludedFiles, sKey) {   if  (aIncludedFiles == null) {     return false;   } }); 
like image 176
alexmac Avatar answered Oct 06 '22 16:10

alexmac