2016-05-24 6 views

Antwort

0

Sie _.each() für dieses

_.each(YourArray, function(p){ 
    if(p.status === "active") p.status = "inactive"; 
    // or 
    p.status = p.status === "active" ? "inactive" : p.status; 
}); 

Aber warum wollen Sie underscore für diese Aufgabe verwenden können? Sie können es mit "Vanille" js lösen:

for(var i = 0, l = YourArray.length; i < l; i++){ 
    if(YourArray[i].status === "active") YourArray[i].status = "inactive"; 
} 

Oder verwenden Array.prototype.forEach()

YourArray.forEach(function(p){ 
    if(p.status === "active") p.status = "inactive"; 
});