jQuery中的each方法

jQuery的each方法可以遍历数组和伪数组,原生的each方法只能遍历数组

<html>

<head>
<title></title>
</head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
        
        $(function(){
            var arr=[1,2,34,]      //数组
            var fakeArray = {      //伪数组
            length: 3,
            "0": "first",
            "1": "second",
            "2": "third"
            };
 
            $.each(arr,function(index,value){     //arr代表要遍历的数组,index遍历数组的索引,value遍历数组的值
                console.log(index,value)
                }
            )
            $.each(fakeArray,function(index,value){
                console.log(index,value)
                }
            )
        })
        
    </script>
    
<body>
</body>
</html>

 

posted @ 2018-10-29 22:29  大C文  阅读(232)  评论(0编辑  收藏  举报