for循环
来源:互联网 发布:淘宝上很赞的杂货店铺 编辑:程序博客网 时间:2024/06/16 16:38
for循环 一般适用数组的遍历, 数组的批量操作
如果您希望一遍又一遍地运行相同的代码,并且每次的值都不同,那么使用循环是很方便的。
JS数组的遍历方法有两种:
第一种:一般的for循环,例如:
var a = new Array("first", "second", "third") for(var i = 0;i < a.length; i++) {document.write(a[i]+",");}
第一种:用for...in 这种遍历的方式,例如:输出的结果:fitst,second,third
1
2
3
4
var arr = new Array("first", "second", "third")
for(var item in arr) {
document.write(arr[item]+",");
}
输出的结果:fitst,second,third
JavaScript 支持不同类型的循环:
- for
- 循环代码块一定的次数 - for/in
- 循环遍历对象的属性 - while
- 当指定的条件为 true 时循环指定的代码块 - do/while
- 同样当指定的条件为 true 时循环指定的代码块
viafor...in 语句用于对数组或者对象的属性进行循环操作。原文来自:http://caibaojian.com/js-loop-for-in.html
for ... in 循环中的代码每执行一次,就会对数组的元素或者对象的属性进行一次操作。
Tip:for-in循环应该用在非数组对象的遍历上,使用for-in进行循环也被称为“枚举”。
1 0
- for循环
- For循环
- for循环
- for 循环
- for循环
- for循环
- for循环
- for循环
- for 循环.
- for 循环
- for循环
- For循环
- for循环
- FOR循环
- for循环
- for循环
- for循环
- for循环
- 选择排序
- CodeForces 445B DZY Loves Chemistry (并查集)
- 机器学习免费课程 Top 10
- nginx 开关机命令
- 用了就懂的float定位
- for循环
- C#系列——多线程通信
- 中文拼音的正则表达式
- python下载网络图片
- 静态加载fragment
- 圆柱直齿轮设计程序-vb
- 1052. Linked List Sorting (25)解题报告
- 数据结构基本概念
- 众数问题