Created
October 5, 2018 11:08
-
-
Save pokorson/4c2771f82c843137e038bcaa9c321236 to your computer and use it in GitHub Desktop.
Javascript shallow copying example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of updating record on shallow copied array in Javascript | |
const arr1 = [{a: 10, b: 15}]; | |
console.log("arr1 before update = ", arr1); | |
const arr2 = arr1.slice(); | |
console.log("arr2 before update = ", arr2); | |
arr2[0].b = 15; | |
console.log("arr2 after update = ", arr2); | |
console.log("arr1 after update = ", arr1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment