How to use each() in jQuery?
The jQuery each function is used to iterates through DOM elements similar to a foreach loop in other languages. This function iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. The call back function is triggered in the context of the current DOM element, so you can use this keyword to refer the currently matched element.
- index - The index position of the element
- element - The current element
Loop Through Arrays
jQuery $.each() works for objects and arrays both.