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

  • SEARCH
  • Home
  • 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 9142175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:44:34+00:00 2026-06-17T09:44:34+00:00

I’m working on an angular app and am running into a problem. I’m fairly

  • 0

I’m working on an angular app and am running into a problem. I’m fairly new to JS and very new to asynch programming so I’m guessing I’m missing something obvious.

The gist of the problem is that I have a for loop which builds an array. I then need to join that array as soon as the for loop has completed it’s business. Normally this would be a no brainer but apparently in angular the for loop executes asynchronously. I need to force my array join to happen after the for loop exits.

if(!data.results[i].is_deleted) {
  var objectsOnCurrentPermission = new Array();
  if(data.results[i].objects) {
    for(var j = 0; j < data.results[i].objects.length; j++) {
      var currentObjectId = data.results[i].objects[j].object_id;
      var currentObjectName;
      var objectData = Object.get({id: currentObjectId}, function(objectData) {
        objectsOnCurrentPermission.push(objectData.name);
        console.log('in loop in get fn');
        console.log(objectsOnCurrentPermission);
      });
    }
    console.log('after loop');
    console.log(objectsOnCurrentPermission);
    var listOfObjectsOnCurrentPermission = objectsOnCurrentPermission.join(', ');
    console.log('str after assignment');
    console.log(listOfObjectsOnCurrentPermission);
    data.results[i]['objects_list'] = listOfObjectsOnCurrentPermission;
}

To my surprise, when I inspect the output I see (I added ‘<‘s for readability)

after loop permissions.js:246
>Array[1]
permissions.js:247
str after assignment permissions.js:249

permissions.js:250
in loop in fn permissions.js:242
>Array[1]

You can see that the after loop output executes first. From what I can tell, the first time it outputs Array[1] the array isn’t actually populated – chrome just fills it in after the fact. The the blank line after the line that says “str after assignment” is where I try to output of the join which clearly didn’t work. Then finally the code in the loop executes. As I mentioned I need to make sure that array join happens after the for loop has finished populating the array.

  • 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-17T09:44:35+00:00Added an answer on June 17, 2026 at 9:44 am

    I ended up using caolan’s async library to manage my sync/async code needs. Specifically async.parallel allowed me to build the intermediate arrays and ensure they are complete before moving on. https://github.com/caolan/async

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.