DEV Community

Discussion on: Stop Telling People For Loops Are Bad

Collapse
 
krivkoo profile image
Matej Krivonak • Edited

For breaking a loop in javascript you can use .some() functional method, which return false as default, but you can return true (with a break functionality), when your condition passed. For example:

const arrayList = [false, true, false, false];

arrayList.some(arrayItem => {
if (arrayItem === true ) {
// your business logic...
return true;
}
});