<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>09-静态方法each方法</title>
<script src="js/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};
/*
第一个参数: 遍历到的元素value
第二个参数: 当前遍历到的索引index
注意点:
原生的forEach方法只能遍历数组, 不能遍历伪数组
*/
// arr.forEach(function (value, index) {
// console.log(index, value);
// });
// obj.forEach(function (value, index) {
// console.log(index, value);
// });
// 1.利用jQuery的each静态方法遍历数组
/*
第一个参数: 当前遍历到的索引index
第二个参数: 遍历到的元素value
注意点:
jQuery的each方法是可以遍历伪数组的
*/
// $.each(arr, function (index,index) {
// console.log(index, value);
// });
$.each(obj, function (index, value) {
console.log(index, value);
});
</script>
</head>
<body>
</body>
</html>
09-静态方法each方法——jQuery遍历each()方法
最新推荐文章于 2020-04-18 18:24:26 发布