jQuery is a library within javascript that is meant to make tree traversals and handling events like animations easier. Within this library is the each
method. This method is simply an iterator. It will loop over any iterable object or array in order to manipulate elements within it.
The jQuery.each
method takes in two parameters:
The first parameter is the array or object on which the method is to be applied
The second parameter is the callback; this is a function that is applied on every element of the array or object. The callback itself has two parameters:
Note: Keep in mind that if the
each
method is being applied on an array, then the callback will have a number which denotes the index and its corresponding value as arguments. If the method is being run on an object then it will be given a key-value pair as arguments.
each
method on arrayseach
method on a JSON objectFree Resources