所以基本上,我有一个对象数组,我只想更新数组中满足条件的对象。我想知道是否有像解决这个问题的功能良好的方法。现在我正在使用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"}];