What does [literal] in [array/object] mean?

后端 未结 5 808
忘掉有多难
忘掉有多难 2021-01-23 12:20

What does the following syntax mean:

1 in [1,2,3,5]

I know it doesn\'t search for 1 in the array. But what does it do?

I\'ve seen it u

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 13:07

    literalinobject means: "Get a property literal from object."

    When used in a loop, the engine will try to access all properties of the object.

    1 in [1,2,3,4] doesn't check for an occurence of an element with a value of 1, but it checks whether element 1 (array[1]) exists or not.

提交回复
热议问题