Coding / Programming Videos

Post your favorite coding videos and share them with others!

JavaScript Copy Array: How to make an exact copy of an array in JavaScript

Download Video link >



JavaScript Copy Array: How to make an exact copy of an array in JavaScript

In this tutorial, you’ll learn how the JavaScript copy array process works.

Don’t forget to subscribe to the Junior Developer Central channel for more videos and tutorials!

You’ll learn about two ways that JavaScript can be used to copy an array. First, we’ll take a look at the slice function which is a built-in JavaScript function that can be called on an array.

The slice function actually returns back a portion of an array based on the value you supply it as an argument. Typically you would use this to miss the first character from a string (like when using JavaScript to capitalize the first letter of a string). However, in this example, you’ll see that not provided the slice function with a value just returns a complete copy of the entire array and there you have a copy of your original array.

The second method you’ll learn about is the ES6 spread operator which is usually used to insert the values of an entire array into another one. You’ll see in the video that inserting the values into a blank array allows you to create an exact copy.

So JavaScript variables that aren’t primitive data types are copied by reference when you just assign variableA to variableB. It therefore makes sense that a JavaScript array is copied by reference too. In the final section of the video, you’ll see why you can’t just copy a JavaScript array by assigning the variable name to another variable.

Other videos in the JavaScript Snippets series:

JavaScript How To Remove An Item From Array Tutorial: https://youtu.be/UvohHcj9I-s
Javascript String Length: How to determine the size of a string: https://youtu.be/OO0_9gq8NNI
How to find the longest word in a String with JavaScript: https://youtu.be/j9cAav7VIv4
Find the largest number in an array JavaScript Tutorial: https://youtu.be/fOFSmCjvcFY
Check if a String is a palindrome with JavaScript Tutorial: https://youtu.be/_KE_yCKBqUA
How to reverse a String in JavaScript Tutorial: https://youtu.be/k7zzWvQaEhc
JavaScript join method: How to merge arrays into one value: https://youtu.be/90MVWda5DlM
Javascript How To Convert String To Number Tutorial: https://youtu.be/K-Twvsg3K_M
JavaScript Create HTML Element: How to dynamically add tags to your pages: https://youtu.be/VsXCK_2DJzA
JavaScript String Contains: How to check a string exists in another: https://youtu.be/uLT9iPccVZs
Link JavaScript to HTML: How to run your JavaScript code in the browser: https://youtu.be/821C5aJ3SLM
JavaScript Capitalize First Letter: How to make strings and arrays sentence case: https://youtu.be/8IEI-7fj2j4
Javascript Print To Console Tutorial: Different ways to output data to the console: https://youtu.be/pkFbigsR7jI

source

Bookmark(0)
 

 

View Comments source >

Transcript view all >

00:00 in this snippet we'll look at the

00:01 JavaScript copy array task which as a

00:04 junior developer it's something you're

00:06 going to need to know hi this is James

00:13 from junior developer central and

Leave a Reply

Please Login to comment
  Subscribe  
Notify of
Translate »