Underscore.js:使用函数将两个数组与对象组合
Underscore.js: Combining two arrays with objects using a function
我有 2 个包含对象的数组:
first = {
a:false,
b:false,
c:false,
d:false
}
second = {
a:true,
c:true
};
我想得到:
third = {
a:true,
b:false,
c:true,
d:false
}
我正在使用下划线和 jQuery。
我试过 _.union
但它 returns 是一个包含 a&b 所有索引的数组。
您似乎在寻找下划线的 defaults
函数
var third = _.defaults(second, first);
// Object {a: true, b: false, c: true, d: false}
我有 2 个包含对象的数组:
first = {
a:false,
b:false,
c:false,
d:false
}
second = {
a:true,
c:true
};
我想得到:
third = {
a:true,
b:false,
c:true,
d:false
}
我正在使用下划线和 jQuery。
我试过 _.union
但它 returns 是一个包含 a&b 所有索引的数组。
您似乎在寻找下划线的 defaults
函数
var third = _.defaults(second, first);
// Object {a: true, b: false, c: true, d: false}