Reputation: 431
I want to use the _.every method(Not using _.each method because I can't break it _.each loop) for traversing the array and break the traversal on a condition. So I want to know is _.every method is synchronous or not?
Upvotes: 0
Views: 293
Reputation: 6803
Yes it sync
function every(collection, callback, thisArg) {
var result = true;
callback = lodash.createCallback(callback, thisArg, 3);
var index = -1,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
while (++index < length) {
if (!(result = !!callback(collection[index], index, collection))) {
break;
}
}
} else {
forOwn(collection, function(value, index, collection) {
return (result = !!callback(value, index, collection));
});
}
return result;
}
Upvotes: 1