对于...中的字符串数组
这个问题在这里已经有了答案:
  for..in循环for..in枚举属性和数组具有充当索引的数字属性。  它仅与对象一起使用。 
  使用数组这样做也会给你,你不会感兴趣的属性(如那些在原型继承来自上级链性能Object的对象) 
  所以使用一个简单的for循环或Array.forEach 
products.forEach(function(str){
   console.log(str);
});
// or
for(var i = 0; i < products.length; i++)
   console.log(products[i]);
  这是因为在你的情况下,变量x保存数组项的索引,而不是数值。  取而代之的x ,你应该使用products[x] 
products = ["Item1", "Item2", "Item3"];
for (var x in products) {
  debugger;
  console.log(products[x]);
}
现在,而不是:
0
1
2
你会得到
Item1
Item2
Item3
像这样遍历数组。 如果你想遍历一个对象的属性,而不是一个数组,你可以在arr中使用var!
var products = ["Item1", "Item2", "Item3"];
for (var i =0; i< products.length;i++) {
  debugger;
  console.log(products[i]);
  // x === "0" instead of "Item1"
}
                        链接地址: http://www.djcxy.com/p/12075.html
                        
                        
                    