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 7798949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:09:06+00:00 2026-06-02T00:09:06+00:00

Normally, we can do loops for both arrays and objects to iterate over the

  • 0

Normally, we can do loops for both arrays and objects to iterate over the properties/values. But loops are blocking. However, timeouts can be used to simulate an async loop. i managed to do it for an array.

//do stuff

(function asyncLoop(i){

    //do stuff in the current iteration

    if(++i < array.length){
        setTimeout(function(){asyncLoop(i);}, 1);
    } else {
        callback();
    }
}(0));

//do stuff immediately after, while looping

but this model only works while looping in an array, where there is a limiter – the i that gets passed around. is there a way to do this over an object? let’s just say that the object has 50k keys to iterate through, making it unreasonably long.

i already know of this setImmediate (afaik, only newer IE) and WebWorkers(not yet in IE), but i just want to know if it’s possible to just use the same strategy on an object.

  • 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-02T00:09:08+00:00Added an answer on June 2, 2026 at 12:09 am

    There is no async-capable iterator of properties because there’s no way to save the state of where you are in the iterator other than the for (key in obj) loop and you already know that isn’t async-compatible.

    So, just collect all the keys of the object into an array and use the same mechanism you already have to iterate over the array of keys. Arrays have the advantage that they do have a way to save the state of where you are in the iteration by just keeping track of the array index.

    One can get all the keys, either with the Object.keys(obj) ES5 method (via built-in methods or ES5 shim if needed) or you can collect them yourself if you aren’t otherwise using ES5 shims:

    var keys = [];
    for (var i in obj) {
        if (obj.hasOwnProperty(i)) {
            keys.push(i);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

RUBY_PLATFORM is java either way. Normally I can do system checks with uname but
Normally I'm pretty competent with CSS but I just can't figure this one out...
Blocking berkeley sockets normally used by Ruby has one downside: if connection with remote
Normally we can specify a target in the link or use javascript window.open to
Normally with Java Swing you can set the background color of a button with:
Normally when you have a div created in html. You can check its width
A user can import data into our website from a file. The data normally
I was wondering how I can access the keyboard list that you normally access
I want to write a CMakeLists.txt so that I can run my tests normally
On Windows, I normally work with Total Commander, which can easily be configured to

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.