Created
February 15, 2017 17:32
-
-
Save goldhand/5c3d77cbccd23c7b76c82a54050d712c to your computer and use it in GitHub Desktop.
Examples of es6 array destructure assignments
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
| // Array Destructure Assignment Examples | |
| const myArray = ['a', ['b', ['c']], ['d']]; | |
| const oldWayA = myArray[0]; // 'a' | |
| const [newWayA] = myArray; // 'a' | |
| const oldWayB = myArray[1][0][0]; // 'b' | |
| const [,[newWayB]] = myArray; // 'b' | |
| const oldWayC = myArray[1][1][0]; // 'c' | |
| const [,[,[newWayC]]] = myArray; // 'c' | |
| console.log(oldWayA, newWayA); // 'a' 'a' | |
| console.log(oldWayB, newWayB); // 'b' 'b' | |
| console.log(oldWayC, newWayC); // 'c' 'c' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment