Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Array.prototype.forEachRecursive = function (callback, startIndex = 0, index = startIndex) {
if (index >= this.length) {
return;
}
const shouldContinue = callback(this[index], index, this);
if (!shouldContinue) {
return; // Break the iteration
}