Undestanding double bracket operation in Javascript

前端 未结 1 617
天命终不由人
天命终不由人 2020-12-03 16:15

What does [1,2,3][1,2] means in Javascript? I do not understand what its supposed to do, and i have no clue how could i google such thing.

Any ideas?

I assum

相关标签:
1条回答
  • 2020-12-03 16:32
    • [1,2,3] is an Array literal
    • <obj>[p] is the bracket notation for property access
    • 1, 2 is a comma operator expression that evaluates to 2

    So the [1,2,3][1,2] as a whole accesses the index 2 of the array, and yields 3.

    0 讨论(0)
提交回复
热议问题