I can't figure out what's going on here... I'm trying to copy an array, and then shuffle and join the copy, but it just isn't cooperating.
I have a JS file and am initializing a new array at the top:
var myArray = [];
On load of this JS file, I am pulling data from the Facebook API and stickin' the results in myArray with some HTML around it.
I then have a function which I call on button click which creates a new variable from myArray and then joins and prints out the text in a div element:
var namesList = myArray;
namesList.join('');
$('#my_div').text(namesList);
It's obviously been simplified, but the premise is the same.
My problem is, the array is not joining like it should. It remains in array form and nothing I've tried has fixed this. I've also tried:
var namesList = myArray.slice();
and
var namesList = myArray.slice(0);
to no avail.
HOWEVER: I can manipulate myArray with no problems in the same function and get the results I need. The problem with that is, I need to be able to shuffle the array each time the function is called and then print it out as text; this is why I am copying it in the first place.
For the life of me I can't figure out why this isn't working. All I need to do here is to create a copy of the variable within the scope of the function I'm calling, shuffle it, join it, and print it.
How do I fix this? OR, is there a better alternate? Many thanks in advance!