1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>jQuery.extend demo</title>
6 <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
7</head>
8<body>
9
10<div id="log"></div>
11
12<script>
13var object1 = {
14 apple: 0,
15 banana: { weight: 52, price: 100 },
16 cherry: 97
17};
18var object2 = {
19 banana: { price: 200 },
20 durian: 100
21};
22
23// Merge object2 into object1
24$.extend( object1, object2 );
25
26// Assuming JSON.stringify - not available in IE<8
27$( "#log" ).append( JSON.stringify( object1 ) );
28</script>
29
30</body>
31</html>
32
1// merge all source objects into target object
2$.extend(targetObj, srcObj1, srcObj2/*, ...srcObjN */ );