{"id":7030,"date":"2025-02-06T07:30:04","date_gmt":"2025-02-06T07:30:04","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7030"},"modified":"2025-02-06T07:39:38","modified_gmt":"2025-02-06T07:39:38","slug":"how-to-merge-two-javascript-objects","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/","title":{"rendered":"How to Merge Two JavaScript Objects"},"content":{"rendered":"\n<p>Web developers commonly use JavaScript object literals to store data as key-value pairs. JS objects can be easily converted into JSON and sent to web servers, and vice versa. Sometimes, you may need to combine the data present in two or more objects. There are several ways to do this using JavaScript. You can do this using plain JavaScript, or using third party JavaScript libraries. In this article, we will learn several different ways to merge JavaScript objects.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#How_to_Merge_Two_JavaScript_Objects\" >How to Merge Two JavaScript Objects<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#1_Using_Spread_Operator\" >1. Using Spread Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#2_Using_Objectassign_method\" >2. Using Object.assign() method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#3_Using_jQuery_extend\" >3. Using jQuery extend()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#Key_Considerations\" >Key Considerations<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#1_Shallow_Copying\" >1. Shallow Copying<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#2_Data_Overwriting\" >2. Data Overwriting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#3_Enumerable_Properties\" >3. Enumerable Properties<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#4_Performance\" >4. Performance<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Merge_Two_JavaScript_Objects\"><\/span>How to Merge Two JavaScript Objects<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some of the most popular ways to merge two JavaScript objects. Let us say you have the following JavaScript objects.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = {'a':1,'b':2};<br>d2 = {'b':3,'d':4};<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Spread_Operator\"><\/span>1. Using Spread Operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The spread operator &#8216;&#8230;&#8217; is a simple and effective way to merge two or more JavaScript objects. Here is its syntax. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{...object1, ...object2}<\/pre>\n\n\n\n<p>Basically, you need to prefix each object that you want to merge with &#8216;&#8230;&#8217; and mention it in curly braces &#8216;{}&#8217;, one after the other in a comma-separated manner.<\/p>\n\n\n\n<p>Please note, the merging of objects happens from left to right. So if there are common keys in the objects, then its value in the rightmost objects will be used in the final merged object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d3={...d1,...d2};<br>console.log(d3); \/\/ output is { a: 1, b: 3, d: 4 }<\/pre>\n\n\n\n<p>You can choose to create a separate merged object as shown above, or merge one object into another.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1={...d1,...d2};<br>console.log(d1); \/\/ output is { a: 1, b: 3, d: 4 }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_Objectassign_method\"><\/span>2. Using Object.assign() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use Object.assign() function to combine two or more JS objects. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Object.assign(object1, object2)<\/pre>\n\n\n\n<p>Here is an example to merge two objects using Object.assign().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d3=Object.assign(d1,d2);<br>console.log(d3); \/\/ output is { a: 1, b: 3, d: 4 }<\/pre>\n\n\n\n<p>Assign() function also merges objects from left to right. So if there are common keys in the individual objects, it will use the value of rightmost object ,in the final merged object.<\/p>\n\n\n\n<p>Like spread operator, you can also use assign() function to create a new object, or overwrite one of the original objects.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1={...d1,...d2};<br>console.log(d1);  \/\/ { a: 1, b: 3, d: 4 }<\/pre>\n\n\n\n<p>Object.assign() function is more compatible with older web browsers, than using Spread operator.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_jQuery_extend\"><\/span>3. Using jQuery extend()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use third-party libraries like <a href=\"https:\/\/jquery.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">jQuery<\/a> to merge JavaScript objects. It provides several functions for this purpose such as extend().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$.extend(object1, object2);<\/pre>\n\n\n\n<p>Here is an example to merge two objects using this function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$.extend(d1,d2);<br>console.log(d1); \/\/ output is { a: 1, b: 3, d: 4 }<br>console.log(d2); \/\/ output is { b: 3, d: 4 }<\/pre>\n\n\n\n<p>Please note, the extend() function, when used as shown above will also modify the original object d1. This is because it merges d2 into d1 and stores the result into d1.<\/p>\n\n\n\n<p>Even if you store the result explicitly in another object, it will still modify one of the original objects.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d3=$.extend(d1,d2);<br>console.log(d3);  \/\/ output is { a: 1, b: 3, d: 4 }<br>console.log(d1); \/\/ output is { a: 1, b: 2 }<br>console.log(d2); \/\/ output is { b: 3, d: 4 }<\/pre>\n\n\n\n<p>So if you do not want the original objects to be modified, then you need to modify the above function as shown below. You need to provide an extra empty object {} as the first argument.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$.extend({},object1, object2);<\/pre>\n\n\n\n<p>Here is how you can merge two objects using extend() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d3=$.extend({},d1,d2);<br>console.log(d3); \/\/ output is {a: 1, b: 3, d: 4}<br>console.log(d1); \/\/ output is {a: 1, b: 2}<br>console.log(d2); \/\/ output is {b: 3, d: 4}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Key_Considerations\"><\/span>Key Considerations<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some factors to consider when you choose an approach to merge objects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Shallow_Copying\"><\/span>1. Shallow Copying<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>All the above solutions only do a shallow copy of objects while merging them. It means that if your objects contain nested data then the data in merged object will continue to point to the data in original objects. However, if your objects are flat with numerical or alphabetical data, then you can use any of these methods, as it will create a separate copy of each data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Data_Overwriting\"><\/span>2. Data Overwriting<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If your objects contain common keys, then their values will be overwritten with the value in rightmost object. So the data in final result depends on the order in which you list your objects in these functions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Enumerable_Properties\"><\/span>3. Enumerable Properties<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>These functions will only merge enumerable properties in objects. They will omit non-enumerable properties. So if your objects contain non-enumerable properties, you need to write a custom function to merge them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Performance\"><\/span>4. Performance<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Although it looks very easy to merge two or more JS object literals, it is important to remember that if your objects contain a lot of data, then it will take some time to merge them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several simple ways to easily merge two or more JavaScript objects. If you are using modern web browsers, you can use Spread operator since it is concise and easy to understand. If you need to compatibility with older web browsers, use Object.assist() function. If your website uses jQuery library, you can also use extend() function for this purpose.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\">How to Check If Key Exists in JS Object<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/\">How to Insert Item Into JS Array<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/what-does-strict-do-in-javascript\/\">What Does Strict Do in JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often web developers need to combine two or more JS objects. Here are different ways to merge two JavaScript objects.<\/p>\n","protected":false},"author":1,"featured_media":7062,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[386],"class_list":["post-7030","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-merge-objects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Merge Two JavaScript Objects - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often web developers need to combine two or more JS objects. Here are different ways to merge two JavaScript objects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Merge Two JavaScript Objects - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often web developers need to combine two or more JS objects. Here are different ways to merge two JavaScript objects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-06T07:30:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-06T07:39:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"285\" \/>\n\t<meta property=\"og:image:height\" content=\"186\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Merge Two JavaScript Objects\",\"datePublished\":\"2025-02-06T07:30:04+00:00\",\"dateModified\":\"2025-02-06T07:39:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\"},\"wordCount\":738,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1\",\"keywords\":[\"merge objects\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\",\"name\":\"How to Merge Two JavaScript Objects - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1\",\"datePublished\":\"2025-02-06T07:30:04+00:00\",\"dateModified\":\"2025-02-06T07:39:38+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often web developers need to combine two or more JS objects. Here are different ways to merge two JavaScript objects.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1\",\"width\":285,\"height\":186,\"caption\":\"merge javascript objects\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Merge Two JavaScript Objects\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/\"],\"url\":\"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Merge Two JavaScript Objects - Ubiq BI","description":"Often web developers need to combine two or more JS objects. Here are different ways to merge two JavaScript objects.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/","og_locale":"en_US","og_type":"article","og_title":"How to Merge Two JavaScript Objects - Ubiq BI","og_description":"Often web developers need to combine two or more JS objects. Here are different ways to merge two JavaScript objects.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-02-06T07:30:04+00:00","article_modified_time":"2025-02-06T07:39:38+00:00","og_image":[{"width":285,"height":186,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Merge Two JavaScript Objects","datePublished":"2025-02-06T07:30:04+00:00","dateModified":"2025-02-06T07:39:38+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/"},"wordCount":738,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1","keywords":["merge objects"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/","name":"How to Merge Two JavaScript Objects - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1","datePublished":"2025-02-06T07:30:04+00:00","dateModified":"2025-02-06T07:39:38+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often web developers need to combine two or more JS objects. Here are different ways to merge two JavaScript objects.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1","width":285,"height":186,"caption":"merge javascript objects"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Merge Two JavaScript Objects"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/merge-javascript-objects.jpg?fit=285%2C186&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Po","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7030"}],"version-history":[{"count":35,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7030\/revisions"}],"predecessor-version":[{"id":7067,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7030\/revisions\/7067"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7062"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}