How do you go from this:
var array = [{key: [3]}, {key1: [3]}, {key1: [3]}]
var object = {key1: [3], key2: [3]};
to this:
{key: [3], key1: [9], key2: [3]}
All "key" are a userIds like "LQVjUacPgK" as seen in the obj example below.
[N] = is an array of N objects each of which has about 10 key value pairs within.
N = {obj, obj, obj};
obj = {_account: "JDQEPxoy3ktZRP9VEzAMtXLa7rXXedhQ4bARq"
_id: "oQER3vznDwikxm1wdLzJFdVjKL6XomcORMxDL"
amount: 170
category: Array[2]
category_id: "21003000"
date: "2015-06-09"Object
type: Object
userId: "LQVjUacPgK"}
Right now I'm doing this:
var test = _.reduce(_.flatten(array.concat([object])),function(a,b){
return _.extend(a, b);
});
}
};
and getting this result instead:
console.log(test)//{key: [3], key1: [3], key2: [3]}
To be clear, the issue is that key1 has different values between all of the objects. I'd like to keep the values from both so that key1: [9].
This is not an underscore answer, but basically I wouldn't use a reduce operation for this and instead do a simple for-each: