如何从数组副本中删除对象而不将其从原始数据中删除?
我有一个全局变量:
var userTrickList = [];
Run Code Online (Sandbox Code Playgroud)
在函数内部,我复制了该全局数组:
var tempUserTrickList = userTrickList;
Run Code Online (Sandbox Code Playgroud)
然后我使用removeItem我创建的函数来删除某个对象.
removeItem(considerTrick.IDName, tempUserTrickList);
function removeItem(item, list) {
//takes a string as 'item', finds in the array as 'list',
//then removes it from the list.
for(var i = 0; i < list.length; i++)
{
if(item === list[i])
{
list.splice(i,1);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,这个功能也将它从中删除userTrickList了.
有任何想法吗?这绝对是一个问题"removeItem(considerTrick.IDName, tempUserTrickList);",但我想不出解决方案.