What is the difference between ( for… in ) and ( for… of ) statements in JavaScript?

前端 未结 14 1294
慢半拍i
慢半拍i 2020-11-22 06:22

I know what is for... in loop (it iterates over key), but heard the first time about for... of (it iterates over value).

I am confused with

14条回答
  •  有刺的猬
    2020-11-22 06:46

    Here is a useful mnemonic for remembering the difference between for...in Loop and for...of Loop.

    "index in, object of"

    for...in Loop => iterates over the index in the array.

    for...of Loop => iterates over the object of objects.

提交回复
热议问题