i can't copy the array
This question already has an answer here:
Arrays are objects, unlike the primitive types like string, int, etc ... variables that take objects correspond to references (pointer) for objects, rather than the object itself, so different variables can reference the same object. Variable of primitive type (string, int, etc.) are associated to values.
In your case you will have to clone your object array for have the same values.
var Mycollection = new Array("James","Jonh","Mary");
var Mycollection2 = Mycollection.slice();
JavaScript通过引用传递数组,以使单独的数组执行:
var Mycollection = new Array("James","Jonh","Mary");
var Mycollection2 = Mycollection.slice();
just use:
var Mycollection2 = Mycollection.slice(0);
to copy the array
链接地址: http://www.djcxy.com/p/20810.html下一篇: 我无法复制数组