I have a function to describe my problem:
function testingFunc(value) {
var temp = value;
console.log("temp before: " + JSON.stringify(temp));
console.log("arrayTest before: " + JSON.stringify(arrayTest));
temp.unshift(123);
console.log("temp after unshift: " + JSON.stringify(temp));
console.log("arrayTest after unshift: " + JSON.stringify(arrayTest));
temp.push(456);
console.log("temp after push: " + JSON.stringify(temp));
console.log("arrayTest after push: " + JSON.stringify(arrayTest));
temp.shift();
console.log("temp after shift: " + JSON.stringify(temp));
console.log("arrayTest after shift: " + JSON.stringify(arrayTest));
temp.pop();
console.log("temp after pop: " + JSON.stringify(temp));
console.log("arrayTest after pop: " + JSON.stringify(arrayTest));
return temp;
}
var arrayTest = [1,2,3,4,5];
var arrayTestTwo;
arrayTestTwo = testingFunc(arrayTest);
console.log("arrayTest after testingFunc: " + JSON.stringify(arrayTest));
console.log("arrayTestTwo: " + JSON.stringify(arrayTestTwo));
As you can see, arrayTest will change too if temp change by using push, unshift, pop and shift to edit it's data.
But I want those function to work ONLY with temp and ignore arrayTest.
Is it possible? Also is it possible to work with object contains functions?
And why is this happen?