{"id":897,"date":"2022-07-12T21:26:14","date_gmt":"2022-07-12T15:26:14","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=897"},"modified":"2022-07-12T21:26:14","modified_gmt":"2022-07-12T15:26:14","slug":"how-to-concat-merge-join-two-array-in-javascript-es6","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/how-to-concat-merge-join-two-array-in-javascript-es6.html","title":{"rendered":"How to Concat\/Merge\/Join Two Array in Javascript ES6"},"content":{"rendered":"\n<p>Let&#8217;s say, we have two arrays:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">let arr1 = [1, 2, 3]\nlet arr2 = [5, 6, 7]<\/pre>\n\n\n\n<p>Now, you want to have a third array that merges the two arrays:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">let arr3 = [1, 2, 3, 4, 5, 6]<\/pre>\n\n\n\n<p>To achieve that, you can simply destructure the two arrays and use the result to create another array like following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">let arr3 = [...arr1, ...arr2]\nconsole.log(arr3)\n[1, 2, 3, 4, 5, 6]<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say, we have two arrays: Now, you want to have a third array that merges the two arrays: To achieve that, you can simply destructure the two arrays and use the result to create another array like following:<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[135],"tags":[686,687,137,688],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/897"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=897"}],"version-history":[{"count":1,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/897\/revisions"}],"predecessor-version":[{"id":898,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/897\/revisions\/898"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}