Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:16:46+00:00 2026-06-11T02:16:46+00:00

I run into the situation where I have multiple JQuery Promises in an Array

  • 0

I run into the situation where I have multiple JQuery Promises in an Array

var arrayOfPromises = [ $.Deferred(), $.Deferred(), $.Deferred(), $.Deferred() ]

and need to turn it into a JQuery Promise of an Array

var promiseOfArray = someTransform(arrayOfPromises)

where

promiseOfArray.done(function(anArray){
  alert(anArray.join(","));
});

creates an alert with text

result1,result2,result3,result4

I currently define someTransform in coffeescript as

someTransform = (arrayOfPromises) ->
  $.when(arrayOfPromises...).pipe (promises...) ->
    promises

which transforms to the following javascript

var someTransform,
  __slice = [].slice;

someTransform = function(arrayOfPromises) {
  return $.when.apply($, arrayOfPromises).pipe(function() {
    var promises;
    promises = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
    return promises;
  });
};

Here is a jsFiddle of the result I’m looking for.

I was wondering if there is a better(shorter,cleaner) way to define someTransform to achieve the same result?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:16:47+00:00Added an answer on June 11, 2026 at 2:16 am

    You can just apply the array as the arguments to $.when.

    var promiseOfArray = $.when.apply($, arrayOfPromises);
    

    To make the usage of this clearer, I like adding a method to $:

    $.whenall = function(arr) { return $.when.apply($, arr); };
    

    Now you can do:

    $.whenall([deferred1, deferred2, ...]).done(...);
    

    Update: By default, the done handler gets each result passed as a separate argument; you don’t get an array of results.

    Since you need to handle an arbitrary number of Deferreds, you can use the special implicit arguments object to loop over the results.

    $.whenall([d1, d2, ...]).done(function() {
        for (var i = 0; i < arguments.length; i++) {
            // do something with arguments[i]
        }
    });
    

    If you really just want to join the string result of all your Deferreds, we can employ a little array hackery. arguments is array-like, but is not an Array:

    $.whenall([d1, d2, ...]).done(function() {
        alert(Array.prototype.join.call(arguments, ','));
    });
    

    If you want to return an array of results to your done callback, we can tweak whenall to do it:

    $.whenall = function(arr) {
        return $.when.apply($, arr).pipe(function() {
            return Array.prototype.slice.call(arguments);
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run into a situation where I need to take all the extra
I have run into a situation where I want to ensure that a compound
I seem to run into this situation quite a lot and have yet to
I don't know if you have run into a similar situation but here's a
I've run into a situation (while logging various data changes) where I need to
Every now and then I run into a situation when I need to email
I have a tricky situation in trying to get information from multiple queries into
I'm learning to use Grails and have run into a situation I don't understand
I am working on a Facebook app and have run into a situation where
I have run into a 1-N situation. i.e 1 record in 1st table will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.