0

I am seeing an assignment like this:

const [a] = someArray

Which seems to assign first item from someArray to a constant. If so, it is the same as const a = someArray[0] but in a new way.

Is it true? How is this assignment called so that I could find more information about it?

Sergei Basharov
  • 43,294
  • 56
  • 177
  • 295
  • 1
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment – Sergio Tulentsev Mar 26 '19 at 10:56
  • 1
    destructuring assignment – apple apple Mar 26 '19 at 10:56
  • const [a] = [1, 2, 3] // a = 1 so essentially the Array destructuring-assignment is a way to access indexed parts of an Array. const [a, ...rest] = [1, 2, 3] // a = 1, rest = [2, 3] const [first, second, third] = [1, 2, 3] // first = 1, second = 2, third = 3 – Francis Leigh Mar 26 '19 at 11:01

0 Answers0