I have
const arrayOfObjects = [{
"id": 123, // Id I want to use to map
"date": 20172301,
"model": 2017
},
{
"id": 221, // Id I want to use to map
"date": 20172301,
"model": 2015
},
{
"id": 1, // Id I want to use to map
"date": 20172301,
"model": 2012
}];
and
const object = {
"123": { // Id I want to use to map
"id": 1 // I am also getting this Id that I don't want
"uri": "www.google.com"
},
"221": { // Id I want to use to map
"id": 2 // I am also getting this Id that I don't want
"uri": "www.bing.com"
}
};
I want
result = [{
"id": 123,
"date": 20172301,
"model": 2017,
"uri": "www.google.com"
},
{
"id": 221,
"date": 20172301,
"model": 2015,
"uri": "www.bing.com"
},
{
"id": 431,
"date": 20172301,
"model": 2012
}];
I am doing
const result = _.map(arrayOfObjects, (item) => _.merge(item, _.find(object, {'uri' : item.uri})));
What am I missing here?
P.S. Noob here.
Thanks in advance.
================= Edit: Added the "id" attribute in the const object.