Skip to content

Instantly share code, notes, and snippets.

@themgoncalves
Last active May 27, 2021 09:34
Show Gist options
  • Select an option

  • Save themgoncalves/4deae00d9b37cc14e38002f982d90b5f to your computer and use it in GitHub Desktop.

Select an option

Save themgoncalves/4deae00d9b37cc14e38002f982d90b5f to your computer and use it in GitHub Desktop.
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