Possible Duplicate:
How to short circuit Array.forEach like calling break?
Is there a way so that I can break out of array map method after my condition is met ? I tried the following which throws "Illegal Break Statement" Error.
This is some random example I came up with.
var myArray = [22,34,5,67,99,0];
var hasValueLessThanTen = false;
myArray.map(function (value){
if(value<10){
hasValueLessThanTen = true;
break;
}
}
);
We can do using for
loops, but I wanted to know whether we can accomplish the same using map
method ?