Questions tagged [each]

An iterator function or language struct which can be used to iterate over arrays or lists.

A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. Arrays and array-like objects with a length property (such as a function's arguments object) are iterated by numeric index, from 0 to length-1. Other objects are iterated via their named properties.

jQuery.each( array, callback )
// or
jQuery.each( object, callback )
3858 questions
20
votes
3 answers

jQuery: get each element's width and sum them up

How can I get each element's width and sum them up? For instance, here is the HTML:
Run
  • 54,938
  • 169
  • 450
  • 748
20
votes
2 answers

Returning Multiple Values From Map

Is there a way to do: a = b.map{ |e| #return multiple elements to be added to a } Where rather than returning a single object for each iteration to be added to a, multiple objects can be returned. I'm currently achieving this with: a = [] b.map{…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
20
votes
4 answers

jQuery get the input value in an .each loop

I am trying to get the input value in an each loop of a checkbox, i cant figure out how to get this to work, the value keeps outputting as the first checkbox value. $('.custemb, input[name=cb], input[class=multadd]').live("click", function() { …
JimmyBanks
  • 4,178
  • 8
  • 45
  • 72
19
votes
1 answer

JQuery $.each() JSON array object iteration

I am having some real difficulty attempting to solve a JQuery $.each() iteration This is my array, limiting results for convenience [{"GROUP_ID":"143", "GROUP_TYPE":"2011 Season", "EVENTS":[ {"EVENT_ID":"374","SHORT_DESC":"Wake Forest"}, …
Jay Rizzi
  • 4,196
  • 5
  • 42
  • 71
19
votes
1 answer

In Ruby, what's the advantage of #each_pair over #each when iterating through a hash?

Let's say I want to access the values of a hash like this: munsters = { "Herman" => { "age" => 32, "gender" => "male" }, "Lily" => { "age" => 30, "gender" => "female" }, "Grandpa" => { "age" => 402, "gender" => "male" }, "Eddie" => { "age"…
clockworkpc
  • 628
  • 1
  • 6
  • 16
19
votes
1 answer

How to use .promise().done() on $.each json array when done/completed?

I want to perform some action when $.each is done. $.each(someArray, function(index, val) { //---------some async ajax action here per loop --------- $.ajax({...}).done(function(data){...}); }.promise().done(function(){...});…
paocom
  • 235
  • 1
  • 3
  • 8
19
votes
3 answers

Using jQuery to get data attribute values with .each()

I have the following HTML with data attributes - I want to write some jQuery that will loop through the HTML and collect the data attributes and put them into an array - could anyone assist as I'm getting an error. I am trying to use the data()…
Zabs
  • 13,852
  • 45
  • 173
  • 297
19
votes
2 answers

Handlebars nested 'each' syntax - not iterating over each element

I am brand new at this Javascript/JSON/Handlebars thing, and I am having trouble getting a JSON object, with two nested levels, to work in a Handlebars template. I have validated the JSON object with JSONLint, so it is valid JSON code, but I don't…
Cronk
  • 453
  • 1
  • 6
  • 16
18
votes
8 answers

setTimeout and array each

I'm confused with using setTimeout and the each iterator. How can I rewrite the following so that the console outputs each name after a delay of 5 seconds? Currently the code below prints all the names at once after 5 seconds. I would like to: 1)…
Kevin
  • 3,441
  • 6
  • 34
  • 40
17
votes
7 answers

Check if all items have the same class

I built a FAQ page with the option to hide and show the content underneath each question. I have a "Expand all" functionality that let the user display all the questions onclick. When a question is expanded it gets a class of "selected". I am trying…
John
  • 3,529
  • 14
  • 42
  • 48
17
votes
3 answers

about ruby range?

like this range = (0..10) how can I get number like this: 0 5 10 plus five every time but less than 10 if range = (0..20) then i should get this: 0 5 10 15 20
why_
  • 171
  • 1
  • 3
17
votes
3 answers

Create a table in thymeleaf

I'm new to thymeleaf and am trying to make a simple table using an array and an each loop. My code looks like this: Smoke Tests
user3073234
  • 771
  • 5
  • 11
  • 24
17
votes
5 answers

jQuery each callback

How to use callbacks on jQuery each function? I am trying something like: $.each(images, function(key, value) { new_images+= '
  • '+[key]+'
  • '; }, function (){ …
    NoNameZ
    • 785
    • 4
    • 14
    • 22
    16
    votes
    3 answers

    ruby get next value on each loop

    Can I get the next value in an each loop? (1..5).each do |i| @store = i + (next value of i) end where the answer would be.. 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 = 29 And also can I get the next of the next value?
    jovhenni19
    • 450
    • 2
    • 8
    • 24
    16
    votes
    9 answers

    jQuery: Finding duplicate ID's and removing all but the first

    $('[id]').each(function () { var ids = $('[id="' + this.id + '"]'); // remove duplicate IDs if (ids.length > 1 && ids[0] == this) $('#' + this.id).remove(); }); The above will remove the first duplicate ID,…
    ditto
    • 5,917
    • 10
    • 51
    • 88