var array1 = new Array("1","2","3"); var array2; array2 = array1; array1.length = 0; alert(array2); //returns empty
This approach is wrong because javascript is divided into primitive types and reference types (similar to java and c#). Array is a reference class type. array2 gets a reference, so modifications to array1 will affect array2. 2. Use slice() You can use slice() to copy, because slice() also returns an array.
< ;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Array Test
in IE8 Both passed the test under FF3.0 and FF3.0
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn