【发布时间】:2012-04-04 19:51:46
【问题描述】:
只要看看代码,你就会明白我的意思:
var aBackup = [3, 4]; // backup array
var a = aBackup; // array to work with is set to backup array
a[0]--; // working with array..
a = aBackup; // array o work with will be rested
console.log(a); // returns [2, 4] but should return [3, 4]
console.log(aBackup); // returns [2, 4] too but should return [3, 4] too
【问题讨论】:
-
Is there a method to clone an array in jQuery? 的可能重复项——尽管标题/问题中有 jQuery 一词,但解决方案与 jQuery 无关。
-
@FelixKling 抱歉,我没有看到这个副本。每个人都应该投票关闭。
标签: javascript arrays