javascript遍历
来源:互联网 发布:淘宝优惠券群怎么加人 编辑:程序博客网 时间:2024/06/18 05:41
1.for循环遍历
var data =['a','b','c'];
for(var i=0;i<data.length;i++){
alert(data[i]);
}
2.while循环遍历
var j=0;
while(j<data.length){
alert(data[j]);
j++;
}
3.do...while循环遍历
var a = 0;
do{
alert(data[a]);
a++;
}while(a<data.length);
注:此循环先执行do中语句,后进行判断
4.for...in遍历
data.test = 'd';//添加后数组length依然为3
for(var b in data){
alert(b);
alert(data[b]);
}
注:每次遍历b为数组或对象的key。
把我们添加的data.test也遍历出来了
5.for...of遍历
for(var c of data){
alert(c);
}
注:此遍历方式不会把添加的data.test也遍历出来
6.forEach遍历
data.forEach(function (value, index, array) {
// value: 值
// index: 索引
// array: 数组本身
alert(value+index +array);
});
注:可以根据自己需要选择参数
0 0
- javascript遍历
- javascript-遍历
- javascript遍历gridview 控件
- javascript DOM 遍历
- JavaScript递归遍历树
- javascript 遍历 页面控件
- 【JavaScript】遍历数组
- javascript遍历map
- javascript 遍历RadioButtonList
- javascript遍历对象属性
- Javascript Dom树遍历
- JavaScript遍历对象属性
- JavaScript递归遍历树
- JavaScript数组遍历
- JavaScript数组遍历
- javascript遍历JSON
- JavaScript遍历XML总结
- javascript遍历所有标记
- linux 命令
- 4. Median of Two Sorted Arrays
- Git使用详解(30分钟理解Git)
- SpringBoot中配置logback
- ollyScript脱壳脚本 for AHpack(0.1)[-]
- javascript遍历
- com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效
- 解决putty连接报 connection refused
- Linux中文乱码问题终极解决方法
- memcache缓存服务器01
- 简单工厂模式
- Maven jar包无法下载的问题 .lastUpdated
- org.springframework.util.StringUtils 方法commaDelimitedListToStringArray(String str)
- hibernate5.1 entity java代码 和 mapping xml生成