Using Objects in For Of Loops

后端 未结 14 2099
春和景丽
春和景丽 2020-11-28 05:56

Why isn\'t is possible to use objects in for of loops? Or is this a browser bug? This code doesn\'t work in Chrome 42, saying undefined is not a function:

te         


        
14条回答
  •  孤街浪徒
    2020-11-28 06:14

    The for..of loop only supports iterable objects like arrays, not objects.

    To iterate over the values of an object, use:

    for (var key in test) {
        var item = test[key];
    }
    

提交回复
热议问题