TODAY I LEARNED

How to use object destructuring with the index over an array?

const names = ['Roy', 'Liz', 'Sofia', 'Clau']

const {
  0: zero,
  1: one,
  2: two,
  3: three,
} = names

console.log(zero) // 'Roy'

Tweet

Learned by rogelio-alatorre on Jun 28, 2022

Discover our latest blog posts
  • #javascript
  • view raw
  • permalink
  • 2 likes
previous TIL next TIL
  • Log in
  • ?

    TIL is an open-source project by MagmaLabs that exists to catalogue the sharing & accumulation of knowledge as it happens day-to-day. Posts have a 200-word limit, and posting is open to any MagmaLaber as well as selected friends of MagmaLabs. We hope you enjoy learning along with us.

    • /wearemagmalabs
  • statistics
  • search
  • Twitter