Last active
June 26, 2021 22:22
-
-
Save siddharth-sunchu/78750daf4d19cfb1e7172f64098aa840 to your computer and use it in GitHub Desktop.
Arrays-SpreadOperator
This file contains hidden or 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
| console.log("********Nested ARRAYS********"); | |
| const c = [1, 2, [3, 4]]; | |
| const d = [...c]; | |
| console.log('c => ', c); | |
| console.log('d => ', d); | |
| /* | |
| c => [ 1, 2, [ 3, 4 ] ] | |
| d => [ 1, 2, [ 3, 4 ] ] | |
| */ | |
| d[0] = 0; | |
| d[2][1] = null; | |
| console.log("---------After modification---------"); | |
| /* | |
| Here the nested values of c will change but the first initial value won't. | |
| Because using spread operator it doesn't provide deep copy with nested arrays. | |
| */ | |
| console.log('c => ', c); | |
| console.log('d => ', d); | |
| /* | |
| ---------After modification--------- | |
| c => [ 1, 2, [ 3, null ] ] | |
| d => [ 0, 2, [ 3, null ] ] | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment