var res = 0;
var nums = [1,2,3,4,5,6,7,8,9];
$.each(nums, function(i, v) {
res = v;
if (res === 5) {
return false;
}
return true;
});
console.assert(res === 5);
_.each(nums, function(v, i) {
res = v;
if (res === 5) {
return false;
}
return true;
});
console.assert(res === 9);
// _.someでbreak
_.some(nums, function(v, i) {
res = v;
if (res === 5) {
return true;
}
return false;
});
console.assert(res === 5);
// _.everyでbreak
_.every(nums, function(v, i) {
res = v;
if (res === 5) {
return false;
}
return true;
});
console.assert(res === 5);
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme