Saturday, February 16, 2019

JavaScript array assign issue

When you do something like array2 = array1; you are just setting array2 as a reference to array1. To make a copy of array1 you need to do array2 = array1.slice();


Furthermore, you can not set Array elements with array1.value1 ='1';. What you have done there is convert your array to an Object. So what you really should be doing is:


var array1 = [];
var array2 = [];
array1[0] = 1;
array2 = array1.slice();
array2[1] = 2;

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...