Skip to content

Instantly share code, notes, and snippets.

@anthonybrown
Created September 14, 2019 15:16
Embed
What would you like to do?
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