Take the 2-minute tour ×  I recently started working with jQuery
and was wondering how I would iterate through a collection (an
array or list of items) of items and sum their contents.  Does
jQuery have something like a for-loop like many other languages
do?  Would there be an easy way to implement this - if this
isn't easily do-able?  share|improve this question add comment
3 Answers  up vote 14 down vote accepted  What you are looking
for is the jQuery .each() function - which will allow you to
iterate through any given field(s) and perform an action. Here
are some examples to get you started (just as simple arrays -
check documentation for additional functionality):   var array =
[ "stack", "overflow"];  $.each(array, function() {
//Perform actions here (this) will be your current item
Example: (Summing an array of numbers - alerting the sum)  var
sum = 0;  $.each(array, function() {       sum += (this);
share|improve this answer add comment  $.each(function) and
$(...).each(function) both accurat