Home  >  Article  >  Web Front-end  >  How to use jquery to traverse collection $each()

How to use jquery to traverse collection $each()

一个新手
一个新手Original
2017-09-18 10:37:301606browse


Overview:

$.each() is used to traverse any collection (whether it is an array or an object), if it is an array. Each time the callback function passes in the index of the array and the corresponding value, the method will return the first parameter of the traversed object.

Example:

var arr1 = [ "aaa", "bbb", "ccc" ]; 
$.each(arr1, function(i,val){ alert(i); 
alert(val);
});

alert(i) will output 0, 1, 2
alert(val) will output aaa, bbb, ccc


//通过上边例子即可知道:$.each(arr1, function(i,val){}/**
 * arr1 : 传入的值,需要遍历的数组或者List等等。
 * i : 遍历出来的索引值,即序列号。
 * val : 遍历出来的具体值。
 */

The above is the detailed content of How to use jquery to traverse collection $each(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn