javascript - Break _.each loop -


how break _.each() loop? tried _.every(), looping through data once.

sample code:

    _.each([1,2,3,4,5],function(num){         if(num < 3)           console.log(num)        else{           console.log(num);           return false;        }    }); 

output: 1 2 3 4 5

    _.every([1,2,3,4,5],function(num){         if(num < 3)           console.log(num)        else{           console.log(num);           return false;        }    }); 

output: 1 false

you cannot escape functional foreach loop.

consider using regular loop instead.

const arr = [1,2,3,4,5];  (let = 0; < arr.length; ++i) {     const num = arr[i];     if(num < 3) {        console.log(num)     } else {        console.log('break out');        break;     } } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -