jQuery中each方法
定义:each() 方法规定为每个匹配元素规定运行的函数
使用:$.each(arr,function(index,value){
})
参数:arr:遍历数组 function:回调函数
index: 当前遍历的每一个索引值 value:数据值
返回值:是一个数组:并且默认返回遍历的值
注意点:方法可以遍历伪数组.
使用实例:
var arr = [1,2,3,4,5,6,7,8,8,9];
var obj = {
0:1,
2:8,
3:4
}
$.each(arr,function(index,value){
console.log(index,value);
})
console.log("--------")
$.each(obj,function(index,value){
console.log(index,value);
})
结果: