Merge objects with properties [Lodash]

by Dawid Ryłko

HTML

<!-- Merge objects with properties [Lodash] -->

<a href="https://dawidrylko.com/nie-pisz-w-kolko-tych-funkcji-wykorzystaj-moc-lodasha/" target="_blank">Łączenie obiektów z właściwościami</a>
<br><br>
<div>Lodash: <pre id="lodash">...</pre></div>

JavaScript

// Merge objects with properties [Lodash]

var cars = {
  data: [{ model: 'Ferrari' }, { model: 'Lamborghini' }, { model: 'Opel' }],
};

var owners = {
  data: [{ user: 'Adam' }, { user: 'Robert' }, { user: 'Karol' }],
};

lodash = _.merge(cars, owners);

console.log(lodash); // Object {data: Array[3]}

function stringify(obj) {
	return JSON.stringify(obj, null, 4);
}

document.getElementById("lodash").innerHTML = stringify(lodash);