A library for deep (recursive) merging of Javascript objects

文档:

安装

npm i deepmerge

代码示例

const merge = require('deepmerge');

const a = {
name: 'Tom',
info: {
sex: 0,
age: 23
}
};

const b = {
name: 'Jack',
info: {
sex: 1,
school: 'puk'
}
};

const c = merge(a, b);


console.log(JSON.stringify(c, null, 2));

输出结果

{
"name": "Jack",
"info": {
"sex": 1,
"age": 23,
"school": "puk"
}
}

cdn

<script type=text/javascript src=https://unpkg.com/deepmerge@4.2.2/dist/umd.js></script>