Last active
May 27, 2021 09:34
-
-
Save themgoncalves/4deae00d9b37cc14e38002f982d90b5f to your computer and use it in GitHub Desktop.
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
| const species = ['octopus', 'squid', 'shark', 'seahorse', 'starfish', 'whale',]; | |
| // TRADITIONAL WAY | |
| const firstItem = species[0]; | |
| const lastItem = species[species.length - 1]; | |
| // NEW WAY WITH SMART ACCESS | |
| const { 0: firstItem, [species.length / 2]: middleItem, [species.length - 1]: lastItem } = species; | |
| console.log(firstItem, middleItem, lastItem); | |
| // outputs: 'octopus', 'seahorse', 'whale' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment