码迷,mamicode.com
首页 > 编程语言 > 详细

jQuery的each可以遍历伪数组

时间:2020-03-01 19:31:31      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:注意   htm   set   log   遍历   script   for   charset   head   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>09-静态方法的each方法</title>
<script src="../js/jquery-3.4.1.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);//报错
})*/

//利用jQuery静态的each方法
/**
* 第一个参数:遍历到的索引
* 第二个参数:遍历到的元素
* 注意点:
* jQuery的each方法可以遍历伪数组的
*/
/* $.each(arr,function (index,value) {
console.log(index,value);
});*/
$.each(obj,function (index,value) {
console.log(index,value);
});

</script>
</head>
<body>

</body>
</html>

jQuery的each可以遍历伪数组

标签:注意   htm   set   log   遍历   script   for   charset   head   

原文地址:https://www.cnblogs.com/god1/p/12391369.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!