我有两个数组的问题。每当我使用下面显示的代码更改一个数组中的值时,另一个数组也会得到相同的更改,这不是预期的。如果我将下面的代码复制并粘贴到浏览器的 javascript 控制台中,我会遇到在调用 ConvertDataArrayToLocationArray(dataArray) 后更改 originalArray 的问题
let originalArray = [
{
"date": "2018-11-16",
"type": "Entertainment",
"location": "Oslo",
"amount": 1024
},
{
"date": "2018-11-16",
"type": "Food",
"location": "Oslo",
"amount": 170
},
{
"date": "2018-11-17",
"type": "Food",
"location": "Fredrikstad",
"amount": 99
},
{
"date": "2018-11-18",
"type": "Food",
"location": "Halden",
"amount": 29
},
{
"date": "2018-11-19",
"type": "Entertainment",
"location": "Oslo",
"amount": 34
},
{
"date": "2018-11-20",
"type": "Entertainment",
"location": "Oslo",
"amount": 15
},
{
"date": "2018-11-20",
"type": "Food",
"location": "Fredrikstad",
"amount": 80
},
{
"date": "2018-11-23",
"type": "Transportation",
"location": "Stavanger",
"amount": 95
},
{
"date": "2018-11-28",
"type": "Entertainment",
"location": "Oslo",
"amount": 1024
},
{
"date": "2018-11-29",
"type": "Food",
"location": "Oslo",
"amount": 117.39
},
{
"date": "2018-11-30",
"type": "Transportation",
"location": "Fredrikstad",
"amount": 29
},
{
"date": "2018-12-2",
"type": "Transportation",
"location": "Stavanger",
"amount": 184
},
{
"date": "2018-12-3",
"type": "Entertainment",
"location": "Oslo",
"amount": 34
},
{
"date": "2018-12-4",
"type": "Food",
"location": "Oslo",
"amount": 162
},
{
"date": "2018-12-4",
"type": "Food",
"location": "Fredrikstad",
"amount": 231
}
];
我的例外结果是称为 originalArray 的变量保持不变,我从 ConvertDataArrayToLocationArray(dataArray) 的返回值中得到一个新数组。
偶然的你
一只甜甜圈
相关分类