I'm trying to pass a global defined array as an argument to a function. I thougt this function would treat the argument as a local variable. But it doesn't... Changing the (in my opinion) local variable also changes the values of the global array. What am I doing wrong?
clickX = [];
for(var i=0; i<10; i++) {
clickX[i] = i;
}
doThis(clickX);
function doThis(x) {
for(var i=0; i<x.length; i++) {
x[i]++;
alert(clickX[i]); // this alerts the changed value of x[i] and not the origin value of the global array
}
}
jsfiddle: https://jsfiddle.net/n546rq89/