Home > Web Front-end > Front-end Q&A > What is the function of each() in jquery?

What is the function of each() in jquery?

青灯夜游
Release: 2022-04-28 17:35:53
Original
2457 people have browsed it

In jquery, each() is a traversal function that can be used to traverse specified objects and arrays. This function accepts two non-omitable parameters. The first parameter specifies the object or array that needs to be traversed. The second parameter specifies the callback function for loop execution; the syntax is "$.each(object,callback)".

What is the function of each() in jquery?

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, each() is a traversal function that can be used to traverse specified objects and arrays.

$.each() accepts two parameters that cannot be omitted:

Parameters Description
object Object type specifies the object or array to be traversed.
callback Function type The specified callback function for loop execution.

Example 1: Traverse array elements

<script src="js/jquery-1.10.2.min.js"></script>
<script>
	$(function() {
		$.each([52, 97], function(index, value) {
			console.log(index + &#39;: &#39; + value);
		});
	})
</script>
Copy after login

What is the function of each() in jquery?

Example 2: Traverse object properties

<script src="js/jquery-1.10.2.min.js"></script>
<script>
	$(function() {
		var obj = {
				"flammable": "inflammable",
				"duh": "no duh"
			};
		$.each(obj, function(key, value) {
			console.log(key + &#39;: &#39; + value);
		});
	})
</script>
Copy after login

What is the function of each() in jquery?

【Recommended learning: jQuery video tutorial, web front-end video

The above is the detailed content of What is the function of each() in jquery?. 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