What if you want a copy of your array? You would probably expect that the following would do it:

var a = ["a","b","c"];
var b = a;

Turns out that's probably not what you want. The variable a really just points to the place in the computer memory where the array values are stored. When you set b=a, you are just saying, point b at the same place!

This means that if we change a[1] we are also changing b[1]. What we really want is a fresh new copy of a that is totally independent of the original.

Luckily, we can use the slice method to do what we want. Note: not to be confused with the splice method from the previous exercise.

var b = a.slice();

This code will create a new array, add every item in array a to it, and assign that new array to variable b. That's more like it!

You can also copy just a part of an array using slice. Just pass in the start and end index of the items you want to copy.

var b = a.slice(1,3)