The jQuery.each() or $.each() can be used to seamlessly iterate over any collection, whether it is an object or an array. However, since the $.each() function internally retrieves and uses the length property of the passed array or object. So, if you it has a property called length — e.g. {en: 'english', length: 5} — the function might not work properly.
Use the
jQuery.each()functionThe
jQuery.each()or$.each()can be used to seamlessly iterate over any collection, whether it is an object or an array. However, since the$.each()function internally retrieves and uses thelengthproperty of the passed array or object. So, if you it has a property calledlength— e.g.{en: 'english', length: 5}— the function might not work properly.Similarly, you can print contents of an object through a loop, as shown below:
need an explanation for this answer? contact us directly to get an explanation for this answer