所以基本上,我有一個對象數組,我只想更新數組中滿足條件的對象。我想知道是否有像解決這個問題的功能良好的方法。現在我正在使用lodash。下面是和示例:有沒有lodash函數或'lodash方式'來做一個條件_.map?
var things = [
{id: 1, type: "a", value: "100"},
{id: 2, type: "b", value: "300"},
{id: 3, type: "a", value: "100"}
];
var results = _.map(things, function (thing) {
if(thing.type === "a") {
thing.value = "500";
}
return thing;
});
// => results should be [{id: 1, type: "a", value: "500"}, {id: 2, type: "b", value: "300"}, {id: 3, type: "a", value: "500"}];