I have code to merge two objects
Here is code
var obj1 = [{ food: 'pizza', car: 'ford'},
{food:'apple',car:'volvo'}];
var obj2 = { animal: 'dog' }
var allRules = Object.assign({}, obj1, obj2);
console.log(allRules);
It works, but in new object I have two elements and dog as 3 element. You can see it from snippet.
But I need two elements with dog as property. So it will be food, car and animal as key in every element of object.
How I can do this?
UPDATE
For merging array with object property I understood, but if I have two arrays like this
var arr1 = [{
food: 'pizza',
car: 'ford'
},
{
food: 'apple',
car: 'volvo'
}
];
var arr2 = [{
animal: 'dog'
},
{animal:'cat'}
];
And want to merge it to one array with 1 element of 1 array, get's 1 element of 2 array , etc.
How I can do this?