ie javascript for in loop vs chrome for in loop

This question already has an answer here:

  • IE8 for…in enumerator 3 answers
  • How do I check if an object has a property in JavaScript? 22 answers

  • using IE11 and looks ok to me

    在这里输入图像描述

    if you want more control use Array.prototype.forEach method.It accepts a callback which have three parameters.They are element,their index and the array itself.Try

    var arr=["test",'ball'];arr.forEach(function(element,index){
       console.log(index);
    });
    

    Use the hasOwnProperty method.

    Example:

    var arr = ["test"];
    for (var e in arr) {
        if (arr.hasOwnProperty(e)) {
            console.log(e);
        }
    }
    

    Good explanation on why this is necessary: https://stackoverflow.com/a/12017703/1387396

    Details on the hasOwnProperty method and its use in for .. in loops: Object.prototype.hasOwnProperty() - JavaScript | MDN

    链接地址: http://www.djcxy.com/p/27312.html

    上一篇: 在枚举中检查定义的项目

    下一篇: 即在循环中使用javascript,在循环中使用chrome