-
红颜莎娜
试试这个:var obj = $.extend(true, a, b);语法:jQuery.extend( [deep ], target, object1 [, objectN ] )深浅拷贝对应的参数就是[deep],是可选的,为true或false。默认情况是false(浅拷贝),并且false是不能够显示的写出来的。如果想写,只能写true(深拷贝)
-
叮当猫咪
原生js 写的function merge (target) { for (let i = 1, j = arguments.length; i < j; i++) { let source = arguments[i] || {}; for (let prop in source) { if (source.hasOwnProperty(prop)) { let value = source[prop]; if(typeof value === "object" ){ target[prop] = merge(target[prop]||{},value) }else { if (value !== undefined) { target[prop] = value; } } } } } return target;};merge(a,b)
-
RISEBY
{...a,...b},望采纳
-
泛舟湖上清波郎朗
Object.assign(a, b) ES6新语法
-
米琪卡哇伊
var a = { title: { text: '饼图', textStyle: { color: '#ffffff', fontSize: 45, fontWeight: 'normal', fontFamily: '华文细黑' }, x: 'center', y: 'center' }}var b = { title: { text: 'PIE', textStyle: { color: '#cccccc' } }, test: 'test'}function merge(target, source) { for (key in source) { if (target.hasOwnProperty(key) && typeof target[key] === 'object') { merge(target[key], source[key]) } else { target[key] = source[key] } }}merge(a, b)console.log(a)