Why is my array being changed?

Tell us what’s happening:
I am pushing cid[i] into my array arr before I change the value of cid[i][1] to 0, but when i return arr, index 1 of every array inside arr has been changed to 0. Why is this happening?

Your code so far


function checkCashRegister(price, cid) {

var arr = [];
for(let i = cid.length-1; i >= 0 ; i--){
    arr.push(cid[i]);
    cid[i][1] = 0
}
return arr;
}

console.log(checkCashRegister(3.26, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

Arrays are objects. This means that they are passed around by reference rather than by value.
If you have

let arr1 = ['a'];
let arr2 = arr1;

You do not have two arrays. The variable arr1 is assigned to “the (newly created) object at memory location X” and then arr2 is assigned to “the object at memory location X”.
So if you do

let arr1 = ['a'];
let arr2 = arr1;
arr2[1] = 'b';

Now arr1 is also ['a', 'b'].

Thanks you. Is there a way i can assign the values of an array into a brand new array?

Sure. The most common way is using .slice().