Due to my limited reputation, I am unable to leave a comment. However, after attempting Mahmoodvcs' solution, I encountered a compile error stating "Cannot find name 'name'."
The key is to declare your variable before the loop begins since it won't be automatically initialized like in a forEach loop. This may seem like a simple fix, but unforeseen issues can arise, so hopefully, this advice proves helpful to someone.
The following code snippet closely resembles the syntax of a forEach loop with the desired functionality:
for(let name of group.names){
if (name == 'SAM') {
break;
}
}
In my case, there was a slight variation. I had placed a return statement inside a forEach loop, intending for it to apply to the encompassing function rather than just the forEach loop. Fortunately, no error was thrown, but discovering this post earlier saved me from potential frustration. Here's how my code evolved:
for(let x of Object.keys(this.ddlForms)) {
if (!(!this.ddlForms[x].filterControl.value || this.ddlForms[x].filterControl.value[0] == 'All' || this.ddlForms[x].filterControl.value.some(y => y == data[this.ddlForms[x].fieldName]))) {//does not meet any of these three conditions
return false;
}
}