Lodash.js – merge() function
A simple Lodash.js example of the merge() function, which merges two objects into one.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="Tizen example"/>
<title>Tizen lodash.js example</title>
<script src="js/lodash.min.js"></script>
</head>
<body>
<div id="first">
</div>
<br>
<div id="second">
</div>
<script>
var firstDiv = document.getElementById('first');
var secondDiv = document.getElementById('second');
var people = {'person1':'Tom', 'person2':'Bart', 'person3':'Nathalie'};
var abilities = {'ability1':'drawing', 'ability2':'programming', 'ability3':'singing'};
firstDiv.innerHTML = "Having two objects:<br><br><br><br>";
Object.keys(people).forEach(function (key) {
firstDiv.innerHTML += "<br>key: " + key + ", value: " + people[key];
});
firstDiv.innerHTML += "<br><br>";
Object.keys(abilities).forEach(function (key) {
firstDiv.innerHTML += "<br>key: " + key + ", value: " + people[key];
});
var result = _.merge(people, abilities);
secondDiv.innerHTML = "<br><br>...we will merge both objects into one, using the same order of the data, from both objects... and we get:<br><br>";
secondDiv.innerHTML += JSON.stringify(result);
</script>
</body>
</html>