각 방법에서 벗어날 수 없습니다. 네이티브 forEachmethod의 동작을 복사하고 네이티브 forEach는 루프 이스케이프를 제공하지 않습니다(예외 발생 제외).
−
와 같은 다른 기능을 사용할 수 있습니다.-
__.find:요소가 발견되면 루프에서 빠져 나옵니다. 예를 들어,
_.find([1, 2, 3, 4], (element) => {
// Check your condition here
if (element === 2) {
return true;
}
// Do what you want with the elements here
// ...
}); -
각각에서 예외를 던집니다. 예를 들어,
try {
_([1, 2, 3, 4]).each((element) => {
// Check your condition here
if (element === 2) {
throw new Error();
}
// Do what you want with the elements here
// ...
})
}
catch (e) {
// Do nothing.
}