I have a few questions/concerns about dojo.forEach() that I'm hoping someone can answer.
(Can't find a post or test that answers.)
1. Does forEach have break and continue ability from within its 2nd arg function?
2. What solutions exist for a "return" to stop the loop and exit function outside of forEach from within loop function.
These are common to native loop constructs. How do I achieve these with forEach?
Test Code
var array = [
{name: "a", flag: false},
{name: "b", flag: true},
{name: "c", flag: true}
]
// return as effective "continue" within forEach loop function
dojo.forEach(array, function(item){
console.log("name: ",item.name);
if (!item.flag){console.log("Effectively continue for forEach"); return;}
console.log("Code to execute if pass condition");
});
// How do I affect a "break" or "return"
function () {
dojo.forEach(array, function(item){
console.log("name: ",item.name);
if (!item.flag){console.log("Stop loop as 'break' or 'return' from forEach loop based on this decision");}
// If 'return' used, returns to calling context without executing anymore items
console.log("Code to execute if pass condition");
});
console.log("Code to continue executing if 'break' encountered.");
}
{name: "a", flag: false},
{name: "b", flag: true},
{name: "c", flag: true}
]
// return as effective "continue" within forEach loop function
dojo.forEach(array, function(item){
console.log("name: ",item.name);
if (!item.flag){console.log("Effectively continue for forEach"); return;}
console.log("Code to execute if pass condition");
});
// How do I affect a "break" or "return"
function () {
dojo.forEach(array, function(item){
console.log("name: ",item.name);
if (!item.flag){console.log("Stop loop as 'break' or 'return' from forEach loop based on this decision");}
// If 'return' used, returns to calling context without executing anymore items
console.log("Code to execute if pass condition");
});
console.log("Code to continue executing if 'break' encountered.");
}

dojo.forEach() cannot
dojo.forEach() cannot terminate a loop (save for throwing an exception). Use dojo.some() or dojo.every() instead.
Thank you.
dojo.every() in this case is exactly what I was looking for.
dojo.filter() is another one I needed.
Thank you.
For an open source project, the documentation is good.
Unfortunately, the documentation does not comment yet on these additional array functions and my previous glance at the API did not register this with me. These seem to fit my needs.
Thank you for a great tookkit.