Created
June 30, 2021 02:52
-
-
Save jhunterkohler/c7dd33ec842f35369b7b64df0a1ad5cd to your computer and use it in GitHub Desktop.
Array with a forEach loop that can be broken out of.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BreakableArray extends Array { | |
forEach(callbackFn, thisArg) { | |
let index = 0; | |
while(index < this.length) { | |
let _break = false; | |
callbackFn.call(thisArg, this[i], index, this, () => _break = true); | |
if(_break) { | |
break; | |
} | |
++index; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment