Use this:
(用这个:)
var newArray = oldArray.slice();
Basically, the slice()
operation clones the array and returns a reference to a new array.
(基本上, slice()
操作将克隆该数组并返回对新数组的引用。)
Also note that: (另请注意:)
For references, strings and numbers (and not the actual object), slice()
copies object references into the new array.
(对于引用,字符串和数字(??而不是实际对象), slice()
对象引用复制到新数组中。)
Both the original and new array refer to the same object. (原始数组和新数组都引用同一对象。)
If a referenced object changes, the changes are visible to both the new and original arrays. (如果引用的对象发生更改,则更改对新数组和原始数组均可见。)
Primitives such as strings and numbers are immutable, so changes to the string or number are impossible.
(字符串和数字之类的基元是不可变的,因此无法更改字符串或数字。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…