jquery merge objects code example
Example 1: jquery merge objects
var new_object = $.extend({}, object1, object2);
$.extend(object1, object2);
Example 2: jquery extend
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.extend demo</title>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var object1 = {
apple: 0,
banana: { weight: 52, price: 100 },
cherry: 97
};
var object2 = {
banana: { price: 200 },
durian: 100
};
$.extend( object1, object2 );
$( "#log" ).append( JSON.stringify( object1 ) );
</script>
</body>
</html>