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

后端 未结 5 580
忘掉有多难
忘掉有多难 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:13

    It looks like a cheap way not to use a traditional for loop for each item in the array.

    Your 2nd example is a for-each loop. It doesn't have the literal 1 (one).

提交回复
热议问题