jQuery的each可以遍历伪数组

<!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>

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

时间: 2024-08-30 04:53:43

jQuery的each可以遍历伪数组的相关文章

jquery---调用静态方法-each--map-数组与伪数组的差别

07-jquery对象是一个伪数组-从0开始--到length-1-长度08-静态方法和实例方法 //1.定义一个类 function AClass(){ } //2.给这个类添加以恶搞静态方法 //直接添加给类的就是静态方法 AClass.staticMethod = function(){ alert("这个一个静态方法"); } //静态方法通过类名带调用 AClass.staticMethod(); //3.给这个类添加一个实例放啊 AClass.prototype.insta

javascript 伪数组和转化为标准数组

1: 什么是伪数组 伪数组是一个含有length属性的json对象, 它是按照索引的方式存储数据, 它并不具有数组的一些方法,只能能通过Array.prototype.slice转换为真正的数组,并且带有length属性的对象. var obj = {0:'a',1:'b',length:2}; // 伪数组 var arr = Array.prototype.slice.call(obj); // 转化为数组 console.log(arr); // 返回["a","b&q

JS数组之伪数组以及伪数组转化为标准数组

什么是伪数组? 1,具有length属性 2,能够使用数组遍历方法遍历它们 3,不具有数组的push,pop等方法 哪些是伪数组? 典型的是函数的argument参数,还有像调用getElementsByTagName,document.childNodes之类的,它们都返回NodeList对象都属于伪数组, 诸如var obj5 = { 99: ‘abc’, length: 100 }这样的数据也是伪数组 真数组的判断方法 * 如何判断数据是不是真数组:* 1.数据 instanceof Ar

jquery的each伪数组遍历

jQuery遍历 小结: 也可以利用原型实现伪数组对象转数组 原文地址:https://www.cnblogs.com/jianxian/p/12149986.html

JQuery $.each遍历JavaScript数组对象实例

查看一个简单的jQuery的例子来遍历一个JavaScript数组对象. var json = [ {"id":"1","tagName":"apple"}, {"id":"2","tagName":"orange"}, {"id":"3","tagName":"banana&q

jquery包装器遍历和数组遍历小结

//jquery数组遍历 var arr = [1,2,3]; $.each(arr, function(i,val){ console.log(i); console.log(val); }); 0,1 1,2 2,3 下面这个还可以多看看,高程P96 //js数组遍历 5中 var numbers = [1,2,3,4,5,6]; var everyResult = numbers.every(function(item,index,array){ console.log(item); co

Jquery遍历筛选数组的几种方法和遍历解析json对象|Map()方法详解

一.Jquery遍历筛选数组 1.jquery grep()筛选遍历数组 $().ready( function(){ var array = [1,2,3,4,5,6,7,8,9]; var filterarray = $.grep(array,function(value){ return value > 5;//筛选出大于5的 }); for(var i=0;i<filterarray.length;i++){ alert(filterarray[i]); } for (key in f

jquery $.each遍历json数组方法

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head>  <meta http-equiv="content-

jQuery对象就是伪数组

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>07-jQuery对象</title> <script src="../js/jquery-3.4.1.js"></script> <script> $(function () { var $div= $(