Skip to content

Instantly share code, notes, and snippets.

@anthonybrown
Created September 14, 2019 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonybrown/735ecf75e272570d32134375e9616ccd to your computer and use it in GitHub Desktop.
Save anthonybrown/735ecf75e272570d32134375e9616ccd to your computer and use it in GitHub Desktop.
Object destructuring
function getFirstLast(array) {
const {
0: first,
length: len,
[len - 1]: last
} = array
return {first, last}
}
getFirstLast('Apple')
getFirstLast(['apples', 'grapes', 'peaches', 'pears', 'cherries'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment