1.对象属性遍历

var pricelist={1: "35", 2: "70", 3: "105", 4: "140", 5: "175", 6: "210", 7: "245", 8: "280", 9: "315", 10: "350"};
for (var key in pricelist)
{
console.log(key+"="+pricelist[key])
}
for (attr in window) {
  console.log(attr);
}
//枚举window对象的所有属性

2.数组遍历

方式一:

var pricelist = [35,70,105,140,175,210,245,280,315,350];
for (var key in pricelist)
{
    console.log(pricelist[key])
}

方式二:

var pricelist = [35,70,105,140,175,210,245,280,315,350];
for (var i=0;i<pricelist.length;i++)
{
    console.log(pricelist[i])
}
作者 铁血 汉子 2017年5月8日
2024/11/21/08:39:53pm 2017/5/8/7:44:49
0 2082