js 中的for...in循环

in:其左边是一个字符串或可以转换成字符串,右边是一个对象或数组

例:var person={firstname:"Bob", lastname:"Kin"};

  for(x in person) {

    text = text + person[x];

  }

  document.write(text);//输出BobKin

使用for-in循环也被称为“枚举”,其应该用在非数组对象的遍历上。若用来循环数组,数组对象已被定义的功能增强,可能发生逻辑错误,而且在for-in中,属性列表的顺序不能保证。故,最好数组使用正常的for循环,对象使用for-in循环。

原文地址:https://www.cnblogs.com/jingjing-blog/p/4560664.html