[javascript] How to break out from foreach loop in javascript

I am newbie in Javascrript. I have a variable having following details:

var result = false;
[{"a": "1","b": null},{"a": "2","b": 5}].forEach(function(call){
    console.log(call);
    var a = call['a'];
    var b = call['b'];
    if(a == null || b == null){
        result = false
        break;
    }
});

I want to break the loop if there is NULL value for a key. How can I do it?

This question is related to javascript

The answer is


Use a for loop instead of .forEach()

var myObj = [{"a": "1","b": null},{"a": "2","b": 5}]
var result = false

for(var call of myObj) {
    console.log(call)
    
    var a = call['a'], b = call['b']
     
    if(a == null || b == null) {
        result = false
        break
    }
}