Skip to content

Instantly share code, notes, and snippets.

@HunterKohler
Created June 30, 2021 02:52
Show Gist options
  • Save HunterKohler/c7dd33ec842f35369b7b64df0a1ad5cd to your computer and use it in GitHub Desktop.
Save HunterKohler/c7dd33ec842f35369b7b64df0a1ad5cd to your computer and use it in GitHub Desktop.
Array with a forEach loop that can be broken out of.
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