Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

copying arrays in javascript without reference | copying arrays using spread operator

let arr1 = [1,2,3,4,5];
let arr2 = [...arr1];
arr2[0] = -2;
console.log(arr2);// outputs : [-2,2,3,4,5]
console.log(arr1);// outputs : [1,2,3,4,5]
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #copying #arrays #javascript #reference #copying #arrays #spread #operator
ADD COMMENT
Topic
Name
8+1 =