Home > Article > Web Front-end > What are the ways to traverse arrays and objects using jquery
grep
grep() method is used to filter array elements
grep(array,callback,invert)
array: array to be filtered;
callback : Process each element in the array and filter the elements. This function contains two parameters. The first is the value of the current array element, and the other is the subscript of the current array element, that is, the element index value. This function should return a boolean value. Alternatively, this function can be set to a string, which, when set to a string, is treated as a "lambda-form" (short form?), where a represents the array element and i represents the element index value. For example, "a > 0" represents "function(a){ return a > 0; }"
invert: Boolean optional, the default value is false, the value is true or false, if " "invert" is false or set, the function returns the elements in the array that are returned true by the filter function. When "invert" is true, the function returns the set of elements that are returned false by the filter function
each
How to use each
There is an each method in jQuery, which is very fun to use. You don’t have to write it like the original for loop, there are many uses of each method in the jQuery source code.
In fact, the each method in jQuery is implemented through the call method in js.
inArray
jQuery.isArray(obj) is new in jQuery 1.3. Tests whether the object is an array. Return value: Boolean
Parameters: objObject Object used to test whether it is an array
Example: Check whether it is an array
map
map() passes each element into the current matching collection through the function and generates a new jQuery object containing the return value.
Since the return value is an array encapsulated by jQuery, use get() to process the returned object to get the underlying array. The
.map() method is particularly useful for getting or setting the value of a set of elements. Consider the following form with a series of checkboxes
Traversing the json object:
The above is the detailed content of What are the ways to traverse arrays and objects using jquery. For more information, please follow other related articles on the PHP Chinese website!