Merge plain objects within Array
iniatse opened this issue · 2 comments
iniatse commented
var deepmerge = require('deepmerge');
var isPlainObject = require('is-plain-object');
const target = {
'series': [
{
'innerSize': '75%',
}
]
};
const source = {
'series': [
{
'data': 'bla'
}
]
}
var obj = deepmerge(target, source, {
'isMergeableObject': isPlainObject
})
console.log(obj);
Is it somehow possible at the moment to get the series[0]
object merged such that innerSize
and data
is available on it, while still having isMergeableObject
defined?
iniatse commented
Oh sry it is answered within the documentation. Use 'arrayMerge': combineMerge
, but sadly this does not work in conjunction with 'isMergeableObject': isPlainObject
iniatse commented
I used thw following instead of isPlainObject
, then the problem from the last comment also got solved.
function isMergeableObject(o) {
return isPlainObject(o) || o.constructor.name === 'Array';
}