Ext.each(boundsExtend, function(value) { if(value != record.ID) break; });
So how do I break or continue Ext.each loop?
No, it doesn't, because you pass a callback as a return, which is executed as an ordinary function. All forEach does is call a real, actual function you give to it repeatedly, ignore how it exits, then calls it again on the next element.
There is no way to stop or break a forEach() loop other than by throwing an exception. If you need such behavior, the forEach() method is the wrong tool.
From the docs:
If the supplied function returns false, iteration stops and this method returns the current index.
So as in the OP's example (assuming record
is in scope and non-null):
Ext.each(boundsExtend, function(value) { if (value != record.ID) { return false; } // other logic here if ids do match });
Note that returning false
exits the loop completely, so in this case the first non-matching record will bypass any additional checking.
However I'm guessing that what you're really trying to do is loop until you find the matching record, do some logic, then short-circuit the loop. If that's the case, the logic would actually be:
Ext.each(boundsExtend, function(value) { if (value === record.ID) { // do your match logic here... // if we're done, exit the loop: return false; } // no match, so keep looping (i.e. "continue") });
Any other value that is not explicitly false
(e.g. null
by default) will keep the loop going.
var countries = ['Vietnam', 'Singapore', 'United States', 'Russia']; Ext.Array.each(countries, function(name, index, countriesItSelf) { console.log(name); }); Ext.Array.each(countries, function(name, index, countriesItSelf) { if (name === 'Singapore') { return false; // break here } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With