我是Javascrript的新手。我有一个变量有以下细节:
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;
}
});
如果键的值为NULL,我想打破循环。我该怎么办?
答案 0 :(得分:47)
不要使用.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
}
}