Edit in JSFiddle

// Merge objects [Lodash]

var object1 = {
	a: {
		a1: 'test1',
		a2: 'test2',
	},
	b: {
		b1: 'test3',
		b2: 'test4'
	},
	c: 'test5'
}

var object2 = {
	d: 'test6'
}

// Basic merge function
function merge(test1, test2) {
	var merge = {};
	
	for (var i in test1) {
		merge [ i ] = test1 [ i ];
	}
	for (var j in test2) {
		merge [ j ] = test2 [ j ];
	}
	
	return merge;
}

// Lodash
var lodash = _.merge(object1, object2);

console.log(merge(object1, object2)); // Object {a: Object, b: Object, c: "test5", d: "test6"}
console.log(lodash); // Object {a: Object, b: Object, c: "test5", d: "test6"}