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

前端 未结 14 1551
慢半拍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:41

    for in loops over enumerable property names of an object.

    for of (new in ES6) does use an object-specific iterator and loops over the values generated by that.

    In your example, the array iterator does yield all the values in the array (ignoring non-index properties).

提交回复
热议问题