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
37
votes
3 answers

$().each vs $.each vs for loop in jQuery?

I Can't understand why it is happening. I read here that : The first $.each constitutes a single function call to start the iterator. The second $(foo.vals).each makes three function calls to start the iterator. The first is to the $()…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
36
votes
5 answers

Using .each on dynamic objects in jQuery?

There are lots of questions that seem to be asking this, but in the end all they want is to attach .click events and not .each and so the generally accepted answer in all of them include $("body").on("click", ".selector", function(){}); and this is…
o_O
  • 5,527
  • 12
  • 52
  • 90
34
votes
5 answers

Should I use jQuery.each()?

I'm doing very frequent iterations over arrays of objects and have been using jQuery.each(). However, I'm having speed and memory issues and one of the most called methods according to my profiler is jQuery.each(). What's the word on the street…
pr1001
  • 21,727
  • 17
  • 79
  • 125
33
votes
3 answers

Exit not only from child function but from whole parent function

Short What I want to do is following: At first, function validate() must check all inputs one by one: if they are not empty (or whitespaced) then move to if statement (for checking radio buttons) But if some of inputs empty then stop whole validate…
Tural Ali
  • 22,202
  • 18
  • 80
  • 129
33
votes
2 answers

jQuery looping .each() JSON key/value not working

I am having problems in looping the key/value of JSON by jQuery .each() function Initially I have a JSON like this: json = {"aaa":[ {"id":"1","data":"aaa1data"} ,{"id":"2","data":"aaa2data"} ], …
passer
  • 634
  • 2
  • 8
  • 16
33
votes
4 answers

Ruby array access 2 consecutive(chained) elements at a time

Now, This is the array, [1,2,3,4,5,6,7,8,9] I want, [1,2],[2,3],[3,4] upto [8,9] When I do, each_slice(2) I get, [[1,2],[3,4]..[8,9]] Im currently doing this, arr.each_with_index do |i,j| p [i,arr[j+1]].compact #During your arr.size is a odd…
beck03076
  • 3,268
  • 2
  • 27
  • 37
30
votes
3 answers

jQuery.each - Getting li elements inside an ul

I have this HTML on my page:
    • TEXT1
  • TEXT2
  • .. …
rusben
  • 646
  • 1
  • 6
  • 13
29
votes
4 answers

jQuery .each() with input elements

//save tablet jQuery("#savetablet"+jTablets[i].idtablets).on('click', function() { alert("alertsepy2..."); console.log(jTablets[i].idtablets); jQuery("#tablet"+jTablets[i].idtablets+" .detailsrow").each(function( index ) { …
Eae
  • 4,191
  • 15
  • 55
  • 92
29
votes
1 answer

Get list of data-foo attributes for set of jQuery elements

I can use attr to "Get the value of an attribute for the first element in the set of matched elements ..." To get the list of attributes, do I need to build it up manually with $(..).each or is there a convenience? $('tr.food-row') [
Skylar Saveland
  • 11,116
  • 9
  • 75
  • 91
28
votes
7 answers

Rails 3.1: Ruby idiom to prevent .each from throwing exception if nil?

Is there a way to use .each so it does not throw an error if the object is nil or empty (without adding an additional nil/blank test? It seems that if I say phonelist.each do |phone| that if phonelist is empty, then the block should not be…
jpw
  • 18,697
  • 25
  • 111
  • 187
28
votes
13 answers

How do you find the last loop in a For Each (VB.NET)?

How can I determine if I'm in the final loop of a For Each statement in VB.NET?
RichC
  • 7,829
  • 21
  • 85
  • 149
28
votes
4 answers

jQuery 'each' loop with JSON array

I'm trying to use jQuery's each loop to go through this JSON and add it to a div named #contentHere. The JSON is as follows: { "justIn": [ { "textId": "123", "text": "Hello", "textType": "Greeting" }, { "textId": "514", "text":"What's up?",…
Ben
  • 403
  • 2
  • 5
  • 6
27
votes
1 answer

each loop in underscore.js template

I'm doing something wrong here but I can't see it! Im trying to loop an array in a underscore template. It doesn't work though so I'm missing something, Here's my code, my templates work fine otherwise, it's just the _.each stuff that's bugging…
Joel
  • 3,166
  • 5
  • 24
  • 29
27
votes
5 answers

how to dynamically exit a jquery $.each()?

i have a list of images which i am getting through ajax and then using jquery $.each() i loop through the images and display a image one after the other after an interval of one second. I want the user to be able click on a stop button and so that…
peter
  • 3,411
  • 5
  • 24
  • 27
26
votes
2 answers

Using the jQuery each() function to loop through classname elements

I am trying to use jQuery to loop through a list of elements that have the same classname & extract their values. I have this.. function calculate() { // Fix jQuery conflicts jQuery.noConflict(); jQuery(document).ready(function(){ …
Brett
  • 19,449
  • 54
  • 157
  • 290