5

I have an Array const arr = new Array(100).

And I set

arr[0] = 'A'
arr[49] = 'X'

When destructuring the 1st element, I can do it like:

let [first] = arr

How the statement would be like if I want to access to the 50th element by destructuring expression?

LiuWenbin_NO.
  • 1,216
  • 1
  • 16
  • 25

1 Answers1

11

You can grab the element using object destructuring, like so:

const arr = Array(50).fill(0).map((_, i) => `Element ${i + 1}`)

const {49: fifty} = arr
console.log(fifty)
Kobe
  • 6,226
  • 1
  • 14
  • 35