【发布时间】:2018-04-24 05:20:20
【问题描述】:
所以基本上,我有一个对象数组,我想只更新数组中满足条件的对象。我想知道是否有解决这个问题的好方法。现在我正在使用 lodash。这是和示例:
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"}];
【问题讨论】:
标签: javascript dictionary functional-programming lodash