function nextInLine(arr, item) {
arr.push(item);
var removedItem = arr.shift();
return removedItem;
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr)); //*THIS LINE HERE*
In the above code snippet, why is it that the 3rd console.log line prints [2,3,4,5,6] .. as per my logic, when testArr is passed to the nextInLine function, only a copy of testArr is passed as an argument. Thus, the 3rd console.log line must print [1,2,3,4,5] as it is, without any change!
Any help is appreciated. Thank You.