Javascript Array assignement by reference
If you assign an array to another array, it creates a pointer to it. So any change in the value of one array affects the value of the other.
Take a look at the following example
<html> <body> <script type="text/javascript"> var myArray = [0,1,2,3,4]; var newArray= myArray; newArray[1] = 100; myArray[0] = 50; document.writeln(myArray[1] + '<br>'); document.writeln(newArray[0] + '<br>'); </script> </body> </html> |
Try this example online here .