How can you transform the following array and object:
var array = [{key: [3]}, {key1: [3]}, {key1: [3]}]
var object = {key1: [3], key2: [3]};
into this output:
{key: [3], key1: [9], key2: [3]}
All "key" values represent userIds like "LQVjUacPgK" as shown in the example object below.
[N] = an array of N objects each containing around 10 key-value pairs.
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"}
Currently, the process being used is:
var test = _.reduce(_.flatten(array.concat([object])),function(a,b){
return _.extend(a, b);
});
}
};
However, the current result is different than desired:
console.log(test)//{key: [3], key1: [3], key2: [3]}
The main issue lies with the fact that key1 has varying values across the objects. The goal is to merge these values accordingly so that key1: [9].