{"id":7094,"date":"2025-02-12T04:56:50","date_gmt":"2025-02-12T04:56:50","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7094"},"modified":"2025-02-12T04:56:55","modified_gmt":"2025-02-12T04:56:55","slug":"how-to-copy-array-in-javascript","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/","title":{"rendered":"How to Copy Array in JavaScript"},"content":{"rendered":"\n<p>Web developers commonly use JavaScript arrays to store different types of data. Often they need to clone the data present in one array to another, or create a copy of an array. There are plenty of ways to easily copy array in JavaScript. In this article, we will learn how to clone JavaScript arrays.<\/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-copy-array-in-javascript\/#Why_Copy_Array_in_JavaScript\" >Why Copy Array in JavaScript<\/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-copy-array-in-javascript\/#How_to_Copy_Array_in_JavaScript\" >How to Copy Array in JavaScript<\/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-copy-array-in-javascript\/#1_Using_slice_method\" >1. Using slice() 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-copy-array-in-javascript\/#2_Using_Spread_Operator\" >2. Using Spread Operator<\/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-copy-array-in-javascript\/#3_Using_concat_method\" >3. Using concat() method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#4_Using_map_method\" >4. Using map() method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#5_Using_from_method\" >5. Using from() method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#6_Using_JSON_object\" >6. Using JSON object<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#7_Using_of_method\" >7. Using of() method<\/a><\/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-copy-array-in-javascript\/#8_Using_assign_method\" >8. Using assign() method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Copy_Array_in_JavaScript\"><\/span>Why Copy Array in JavaScript<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The most common reason why developers clone arrays is to perform tasks on its copy without modifying the original array. For example, if you want to process an array in a function without modifying the original array, then you can pass it as an argument to the function. Secondly, if you want to retain the original array for future reference, then you can create its copy and work with it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Copy_Array_in_JavaScript\"><\/span>How to Copy Array in JavaScript<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some of the popular ways to copy array in JavaScript. Before we proceed further, it is good to know that there are two types of copying\/cloning in JavaScript &#8211; deep copy and shallow copy. In deep copy, a new array is created and copies of all the items of original array are newly created, including nested objects and function references. In this case, the cloned array and original array are completely independent of each other. <\/p>\n\n\n\n<p>On the other hand, in shallow copy, only the top level items are copied, whereas nested objects and function references in cloned array continue to point to the original array&#8217;s items. In this case, if you modify the nested objects and function references in cloned array, then it will also modify those items in original array. If your array contains only primary data types like numbers and strings, then both deep copy and shallow copy will be the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_slice_method\"><\/span>1. Using slice() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>slice() method returns a copy of a subset of an array, without changing original array. It is a built-in method available for every array. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">array.slice(start, end)<\/pre>\n\n\n\n<p>In the above command, you need to specify the start and end position of the items to be extracted and returned. They are both optional and can be omitted. If you do not specify them, then slice() method will return a copy of the entire array. Here is an example to demonstrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=a.slice();<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>Please note, the new array will be a shallow copy of original array. If you have basic data types like numbers and strings, then their clones will be present in new array. If you have references to functions and other complex data types, then they will continue to refer to the original array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_Spread_Operator\"><\/span>2. Using Spread Operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Using Spread operator is another simple way to clone a JavaScript array. It basically unpacks an array into its individual items and copies them into another array. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">new_array = [...old_array]<\/pre>\n\n\n\n<p>Here is an example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=[...a];<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>This method also creates a shallow copy of the array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_concat_method\"><\/span>3. Using concat() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>JavaScript provides concat() method to concatenate two or more arrays. While concatenating arrays, it creates a copy to store the result of concatenated arrays. So it can also be used to copy an array. You can do this by concatenating the array you want to copy with an empty array, as shown.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=[].concat(a);<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>This method also creates shallow copy of an array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_map_method\"><\/span>4. Using map() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Map() method allows you to apply a specific function to all items in an array. You can also use it to clone an array. Here is an example to demonstrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=a.map(x=&gt;x);<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>In our map() function, we simply specify an operation to copy each item from old array to new array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_from_method\"><\/span>5. Using from() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use from() function to copy an array. It allows you to create a new array from an existing array, allowing you to optionally provide a mapping function. Here is an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=Array.from(a);<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>In above code, you simply call from() function from global Array JS object. Here is an example to use from function with map. Here you can customize the kind of mapping that happens. You can even modify the items before copying them into a new array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=Array.from(a, x =&gt; x);<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_JSON_object\"><\/span>6. Using JSON object<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>So far, all the above methods only provide a shallow copy of an array. This works in most of the cases, unless you have references in your arrays. In such cases, you need do to a deep copy, where even the references are created afresh before copying them into a new array. For this purpose, you can use JSON module available in every web browser. Here is an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=JSON.parse(JSON.stringify(a));<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>In the above code, JSON.stringify() function first creates a JSON string using the original array&#8217;s copy. Then JSON.parse() function converts this JSON string into a JS array. In this case, the new array has same data as original array but is completely independent from the original array. If you make any changes to the new array, it will not modify the original array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_Using_of_method\"><\/span>7. Using of() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Array object also supports of() function that allows you to quickly copy an array. It will return the input argument wrapped in an array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=Array.of(a);<br>console.log(b); \/\/ output is [[1, 2, 3]]<\/pre>\n\n\n\n<p>You will see that if you call of() function directly on the original array, the result will be [ [1, 2, 3] ] and not [1, 2, 3]. So you need to use the original array along with spread operator, so that it is unwrapped and only its items are supplied to of() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=Array.of(...a);<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Using_assign_method\"><\/span>8. Using assign() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>JavaScript also provides Object that provides many useful functions to work with all kinds of JS objects. You can also use it to clone an array. It copies all properties from original array to a new empty array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3];<br>b=Object.assign([], a);<br>console.log(b); \/\/ output is [1, 2, 3]<\/pre>\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 how to copy an array in JavaScript. If you want to do a deep copy of an array, you need to use JSON.stringify and JSON.parse as shown in solution #6. If you want to do a shallow copy, then you can use any of the other solutions. Among them, using slice method or spread operator offer simplest and fastest ways to clone an array in JavaScript.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-empty-array-in-javascript\/\">How to Empty Array in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\">How to Merge Two JavaScript Objects<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\">How to Check if Key Exists in JavaScript Object<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often web developers need to clone JavaScript arrays. Here are different ways to copy array in JavaScript.<\/p>\n","protected":false},"author":1,"featured_media":7118,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[388],"class_list":["post-7094","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-copy-array"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Copy Array in JavaScript - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often web developers need to clone JavaScript arrays. Here are different ways to copy array in JavaScript.\" \/>\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-copy-array-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Copy Array in JavaScript - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often web developers need to clone JavaScript arrays. Here are different ways to copy array in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/\" \/>\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-12T04:56:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-12T04:56:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/copy-array-in-javascript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"260\" \/>\n\t<meta property=\"og:image:height\" content=\"173\" \/>\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=\"5 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-copy-array-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Copy Array in JavaScript\",\"datePublished\":\"2025-02-12T04:56:50+00:00\",\"dateModified\":\"2025-02-12T04:56:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/\"},\"wordCount\":1034,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1\",\"keywords\":[\"copy array\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/\",\"name\":\"How to Copy Array in JavaScript - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1\",\"datePublished\":\"2025-02-12T04:56:50+00:00\",\"dateModified\":\"2025-02-12T04:56:55+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often web developers need to clone JavaScript arrays. Here are different ways to copy array in JavaScript.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1\",\"width\":260,\"height\":173,\"caption\":\"copy array in javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-array-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Copy Array in JavaScript\"}]},{\"@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 Copy Array in JavaScript - Ubiq BI","description":"Often web developers need to clone JavaScript arrays. Here are different ways to copy array in JavaScript.","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-copy-array-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Copy Array in JavaScript - Ubiq BI","og_description":"Often web developers need to clone JavaScript arrays. Here are different ways to copy array in JavaScript.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-02-12T04:56:50+00:00","article_modified_time":"2025-02-12T04:56:55+00:00","og_image":[{"width":260,"height":173,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/copy-array-in-javascript.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Copy Array in JavaScript","datePublished":"2025-02-12T04:56:50+00:00","dateModified":"2025-02-12T04:56:55+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/"},"wordCount":1034,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1","keywords":["copy array"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/","name":"How to Copy Array in JavaScript - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1","datePublished":"2025-02-12T04:56:50+00:00","dateModified":"2025-02-12T04:56:55+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often web developers need to clone JavaScript arrays. Here are different ways to copy array in JavaScript.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1","width":260,"height":173,"caption":"copy array in javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-array-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Copy Array in JavaScript"}]},{"@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\/copy-array-in-javascript.jpg?fit=260%2C173&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Qq","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7094","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=7094"}],"version-history":[{"count":27,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7094\/revisions"}],"predecessor-version":[{"id":7122,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7094\/revisions\/7122"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7118"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}