Need some help in understanding arrays in JS - from some code i just tried below, it appears that they are referenced? Is this correct?
const generatedNumbers = [1, 2, 3, 4, 5];
const shuffleArrayNumbers = shuffleArray(generatedNumbers);
shuffleArrayNumbers.shift();
console.log(shuffleArrayNumbers);
console.log(generatedNumbers);
function shuffleArray(array) {
return array.sort(() => Math.random() - 0.5);
}
So I was expecting as shuffleArrayNumbers
is in its own variable it would behave unique, however that's not the case. The two console.log outputs produce the same output.
Could someone explain what's happening and how I can return a unique/new array.
Thanks.