var arr1 = ['a','b','c'];
var arr2 = arr1;
arr2.push('d'); // arr1 = ['a','b','c','d']
As you can see from the example above, if you put arr1 in arr2, it doesn't copy the value to arr2, but arr2 becomes another arr1. That's not what I want, but I want to copy the value in arr1 to arr2. So that the two are independent arrangements. How can we do that?
javascript array
in a very simple way
var newArray = oldArray.slice();
You can do it in this way.
© 2024 OneMinuteCode. All rights reserved.