I wrote a simple function to overwrite an array as follows:
function overwrite(arr) {
let temp = [3, 2, 1];
arr = temp;
}
let myarray = [1, 2, 3];
overwrite(myarray);
console.log(myarray);
[ 1, 2, 3 ]
The console output still shows the original array. How come?
By the way, I did figure out how to do it. I feel like the above approach should've worked but didn't, and so I am curious to know why.