{"id":20502,"date":"2020-07-30T10:45:51","date_gmt":"2020-07-30T17:45:51","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=20502"},"modified":"2023-12-01T03:57:08","modified_gmt":"2023-12-01T11:57:08","slug":"javascript-copy-array","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/","title":{"rendered":"JavaScript Copy Array: A Guide"},"content":{"rendered":"\n<p>In <a href=\"https:\/\/careerkarma.com\/blog\/what-is-javascript\/\">JavaScript<\/a>, copying an array is not as simple as using the assignment operator (=) to create a duplicate. If you&#8217;ve ever tried this, you will be surprised to find out that it only creates a link to the original list. What&#8217;s the deal?<br><\/p>\n\n\n\n<p>In this guide, we&#8217;re going to talk about how to copy a JavaScript array. We&#8217;ll walk through the code for three JavaScript copy array strategies so you can get started copying arrays.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Problem with Copying JavaScript Arrays<\/h2>\n\n\n\n<p>On some level, the &#8220;=&#8221; operator creates a copy of an <a href=\"https:\/\/careerkarma.com\/blog\/javascript-array\/\">array<\/a> into a new <a href=\"https:\/\/careerkarma.com\/blog\/javascript-variables\/\">variable<\/a>. It&#8217;s more of a pointer than a copy though. This is because the &#8220;=&#8221; operator creates a reference to an original array. It does not create a duplicate of the existing array.&nbsp;<br><\/p>\n\n\n\n<p>Let&#8217;s try to create a copy of an array using the <a href=\"https:\/\/careerkarma.com\/blog\/js-comparison\/\">assignment operator<\/a> with no other code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var berries = [&quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;];\nvar fruits = berries;\n\nconsole.log(fruits);<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot; ]<\/pre><\/div>\n\n\n\n<p>It looks like our array has been copied. &#8220;fruits&#8221; contains all the values from our &#8220;berries&#8221; array.<br><\/p>\n\n\n\n<p>Now, let&#8217;s try to add an item to the &#8220;fruits&#8221; array:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>fruits.push(&quot;Melon&quot;);\nconsole.log(fruits);\nconsole.log(berries);<\/pre><\/div>\n\n\n\n<p>We have added &#8220;Melon&#8221; to the fruits array. We then print out the values of &#8220;fruits&#8221; and &#8220;berries&#8221; to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;, &quot;Melon&quot; ]\n[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;, &quot;Melon&quot; ]<\/pre><\/div>\n\n\n\n<p>Both &#8220;fruits&#8221; and &#8220;berries&#8221; contain the same values. That&#8217;s because we have not technically cloned our array. We&#8217;ve just created a reference to it.<br><\/p>\n\n\n\n<p>Any time we manipulate the &#8220;berries&#8221; array, the changes will be made in the &#8220;fruits&#8221; array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Copy a JavaScript Array<\/h2>\n\n\n\n<p>The assignment operator does not copy an array. We&#8217;ve got to use another approach. Luckily for us, there are plenty of ways to create a copy of an array. The top three approaches are:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Using the spread operator<\/li><li>Using a <a href=\"https:\/\/careerkarma.com\/blog\/javascript-for-loop\/\">for loop<\/a><\/li><li>Using Array.from<\/li><\/ul>\n\n\n\n<p>Let&#8217;s discuss these one-by-one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using the Spread Operator<\/h3>\n\n\n\n<p>The spread operator is a feature introduced in JavaScript ES6. It allows you to access the contents of an iterable object. This operator is often used to create a shallow copy of an array.<br><\/p>\n\n\n\n<p>The spread operator consists of three dots, like an ellipsis (&#8230;). Let&#8217;s try to create a copy of our &#8220;berries&#8221; array from earlier:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var berries = [&quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;];\nvar fruits = [...berries];\nfruits.push(&quot;Melon&quot;);<\/pre><\/div>\n\n\n\n<p>We&#8217;ve used the spread operator to create a copy of our array. Let&#8217;s check the values of our arrays to make sure they are correct:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>console.log(berries);\nconsole.log(fruits);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot; ]\n[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;, &quot;Melon&quot; ]<\/pre><\/div>\n\n\n\n<p>The value &#8220;Melon&#8221; was only added to the &#8220;fruits&#8221; array. This is because we used the spread operator to create a duplicate of the &#8220;berries&#8221; array. Now, the &#8220;fruits&#8221; array is its own array. Its values are separate from the &#8220;berries&#8221; array.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using a for Loop<\/h3>\n\n\n\n<p>The tried and true method, using a for loop is a good way to create a copy of an array.<br><\/p>\n\n\n\n<p>This method may not be as favored as the spread operator because it requires more lines of code. With that said, a for loop copies an object well.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var berries = [&quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;];\nvar fruits = [];\n\nfor (var i = 0; i &lt; berries.length; i++) {\n\tfruits[i] = berries[i]\n}<\/pre><\/div>\n\n\n\n<p>We&#8217;ve declared two lists: berries and fruits. Fruits is initially an empty list. Then, we&#8217;ve used a for loop to loop through every item in the &#8220;berries&#8221; list. For each item in the list, the value is copied over to the &#8220;fruits&#8221; array.<br><\/p>\n\n\n\n<p>Let&#8217;s run our test to see if our arrays are separate:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>fruits.push(&quot;Grapefruit&quot;);\nconsole.log(berries);\nconsole.log(fruits);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot; ]\n[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;, &quot;Grapefruit&quot; ]<\/pre><\/div>\n\n\n\n<p>Success! &#8220;berries&#8221; and &#8220;fruits&#8221; are two separate arrays.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using Array.from()<\/h3>\n\n\n\n<p>The <code>Array.from()<\/code> method turns any iterable object into an array. It goes through each item in an iterable and appends it to a new array. This means that it can be used to copy an array.<br><\/p>\n\n\n\n<p>Let&#8217;s create a copy of our &#8220;berries&#8221; array again:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var berries = [&quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;];\nvar fruits = Array.from(berries);<\/pre><\/div>\n\n\n\n<p>This solution, like the spread operator syntax, only takes up two lines of code. It&#8217;s an efficient and concise way of copying an array. Now, let&#8217;s run a test to check our new arrays:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>fruits.push(&quot;Pineapple&quot;);\nconsole.log(berries);\nconsole.log(fruits);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot; ]\n[ &quot;Strawberry&quot;, &quot;Gooseberry&quot;, &quot;Raspberry&quot;, &quot;Pineapple&quot; ]<\/pre><\/div>\n\n\n\n<p>Our arrays have been successfully copied.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Copying an array in JavaScript is easy when you know how.<br><\/p>\n\n\n\n<p>The assignment operator isn&#8217;t enough to copy an array if you want to create a separate version of an array. This is because the assignment operator creates a pointer to an existing array; it does not create a new array.<br><\/p>\n\n\n\n<p>You can create a copy of an array using the spread operator, a for loop, or the <code>Array.from()<\/code> method. Now you&#8217;re ready to copy arrays in JavaScript like an expert.<\/p>\n","protected":false},"excerpt":{"rendered":"In JavaScript, copying an array is not as simple as using the assignment operator (=) to create a duplicate. If you've ever tried this, you will be surprised to find out that it only creates a link to the original list. What's the deal? In this guide, we're going to talk about how to copy&hellip;","protected":false},"author":240,"featured_media":19300,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-20502","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript Copy Array: A Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"There are a number of ways to copy a JavaScript array. On Career Karma, learn the three top approaches for copying an array.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Copy Array: A Guide\" \/>\n<meta property=\"og:description\" content=\"There are a number of ways to copy a JavaScript array. On Career Karma, learn the three top approaches for copying an array.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-30T17:45:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:57:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"707\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\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:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"JavaScript Copy Array: A Guide\",\"datePublished\":\"2020-07-30T17:45:51+00:00\",\"dateModified\":\"2023-12-01T11:57:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/\"},\"wordCount\":737,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/\",\"name\":\"JavaScript Copy Array: A Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg\",\"datePublished\":\"2020-07-30T17:45:51+00:00\",\"dateModified\":\"2023-12-01T11:57:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"There are a number of ways to copy a JavaScript array. On Career Karma, learn the three top approaches for copying an array.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg\",\"width\":1020,\"height\":707},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-copy-array\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Copy Array: A Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript Copy Array: A Guide | Career Karma","description":"There are a number of ways to copy a JavaScript array. On Career Karma, learn the three top approaches for copying an array.","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:\/\/careerkarma.com\/blog\/javascript-copy-array\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Copy Array: A Guide","og_description":"There are a number of ways to copy a JavaScript array. On Career Karma, learn the three top approaches for copying an array.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-30T17:45:51+00:00","article_modified_time":"2023-12-01T11:57:08+00:00","og_image":[{"width":1020,"height":707,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"JavaScript Copy Array: A Guide","datePublished":"2020-07-30T17:45:51+00:00","dateModified":"2023-12-01T11:57:08+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/"},"wordCount":737,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/","url":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/","name":"JavaScript Copy Array: A Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg","datePublished":"2020-07-30T17:45:51+00:00","dateModified":"2023-12-01T11:57:08+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"There are a number of ways to copy a JavaScript array. On Career Karma, learn the three top approaches for copying an array.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-copy-array\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/fabian-grohs-Y2m8QfYlpPY-unsplash.jpg","width":1020,"height":707},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-copy-array\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Copy Array: A Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=20502"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20502\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/19300"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=20502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=20502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=20502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}