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

How to use jquery to traverse collection $each()

一个新手
Release: 2017-09-18 10:37:30
Original
1665 people have browsed it


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);
});
Copy after login

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


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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template