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)".
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 + ': ' + value); }); }) </script>
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 + ': ' + value); }); }) </script>
【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!