I only used shift() method for 'arr1[]', but that method modified 'arr2[]', too. How can fix it?
<script>
var arr1=['a','b','c','d','e'];
var arr2=arr1;
arr2.shift();
alert(arr1);
alert(arr2);
</script>
I only used shift() method for 'arr1[]', but that method modified 'arr2[]', too. How can fix it?
<script>
var arr1=['a','b','c','d','e'];
var arr2=arr1;
arr2.shift();
alert(arr1);
alert(arr2);
</script>
to have a real assignation do
var arr1=['a','b','c','d','e'];
var arr2 = Object.assign([], arr1);
arr2.shift();
console.log ('arr1:', JSON.stringify(arr1));
console.log ('arr2:', JSON.stringify(arr2));