Very very often I do the following error when I need to work on a copy of an array and then the whole code doesn't work and it's always hard to realize what's wrong because it look right but it's not!
Let's have a look at the following code:
var music_genre = ['classic', 'dance', 'metal'];
//copy of the array
var favourite_genre = music_genre;
//extract the last element of the array
favourite_genre.pop();
alert(favourite_genre); //['classic', 'dance']
alert(music_genre); //['classic', 'dance'] TOO!!That's because you need to use the method slice() of the class Array, which returns an independent copy of the array and any modify on it wont affect the original one.
Do something like this:
var favourite_genre = music_genre.slice(0);
favourite_genre.pop();
alert(favourite_genre); //['classic', 'dance']
alert(music_genre); //['classic', 'dance', 'metal']

