how to break the _.each function in underscore.js

后端 未结 11 1893
闹比i
闹比i 2020-11-28 20:49

I\'m looking for a way to stop iterations of underscore.js _.each() method, but can\'t find the solution. jQuery .each() can break if you do

11条回答
  •  不知归路
    2020-11-28 21:33

    I believe if your array was actually an object you could return using an empty object.

    _.({1,2,3,4,5}).each(function(v){  
      if(v===3) return {}; 
    });
    

提交回复
热议问题