For example:
function findIndexOfFirstNonNegative(array) {
array.forEach( (a, i) => { if (a >= 0) { return i; }});
return null;
}
it turns out the return i;
will not return to the caller of the function findIndexOfFirstNonNegative()
, but it will return from the fat arrow function and let the forEach
go on (or even if it is a plain old function instead of fat arrow function, it is the same).
Is there a way to break out and return to the caller?