2015-01-21 53 views

回答

1

你可以这样说:

var test = [ {"testId" : 99, "current" : false }, {"testId" : 10, "current" : false }]; 

test.forEach(function(r) { 
    if (r.testId == 99) { 
     r.current = true; 
    } 
}); 

不知道为什么你想避免循环,也不会从你的问题清楚,如果你想这样做对于满足条件的所有元素(这上面的代码当前是这样做的)或者在第一个之后中断。

JS Fiddle

1
var found = test.filter(function(obj) { 
    return obj.testId == 99; 
})[0]; 
if (found) found.current = true; 
相关问题