I am turning an array of objects in to an object of objects. I added my question inside the code for better understanding.
var arr = [
{key : '11', value : '1100', $$hashKey : '00X' },
{key : '22', value : '2200', $$hashKey : '018' }
];
var result = {};
for (var i = 0; i < arr.length; i++) {
result[arr[i].key] = arr[i];
}
// below changes the original array (arr)
result["11"]["value"]="mike"
// below DOES NOT change the original array (arr)
result["2222"] = {key: "33", value: "deded"}
console.log(arr)
I just dont understand why. I have never assigned result to arr (thus created reference to original array), so why does original array change?
Thanks a lot!