<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>09-静态方法each方法</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
var arr = [1, 3, 5, 7, 9];
var obj = {0:1, 1:3, 2:5, 3:7, 4:9, length:5}; //伪数组
/*
*
*第一个参数:遍历到的元素
* 第二个参数:遍历到的索引
* 注意点:原生的forEach方法只能遍历数组,不能遍历伪数组
*/
arr.forEach(function (value, index) {
console.log(index,value);
});
/*obj.forEach(function (value,index) {
console.log(index,value); //不能遍历
})*/
//1.利用each静态方法遍历数组
//第一个参数:遍历的索引
//第二个参数:遍历的元素
//可以遍历伪数组
$.each(arr,function (index,value) {
console.log(index,value);
});
$.each(obj,function (index,value) {
console.log(index,value);
});
</script>
</head>
<body>
</body>
</html>