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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:27:30+00:00 2026-05-23T19:27:30+00:00

I have an Object of Objects. (because I want to use associative array, so

  • 0

I have an Object of Objects. (because I want to use associative array, so object of objects, not numeric array of objects)

var tasks=new Object();

for(...){
tasks[foo-i]={};
tasks[foo-i].index=....;
tasks[foo-i].name=...;
}

I have a function that’ll output the name of the tasks, but they have to be according to the index in ascending order. So, I’ll have to have a temporary sort-function.
How would you do that?
Thanks

  • 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-05-23T19:27:31+00:00Added an answer on May 23, 2026 at 7:27 pm

    Option 1: Output in order of the keys on the task object:

    Perhaps there is a more elegant way, but this way gets all the tasks keys out of the object, sorts them and then uses the ordered index array to cycle through the original object in key order (if I understood correctly what you’re trying to do).

    var indexArray = [];
    var i;
    for (i in tasks) {
        indexArray.push(i);   // collect all indexes
    }
    indexArray.sort(function(a,b) {return(a-b);});  // sort the array in numeric order
    for (i = 0; i < indexArray.length; i++) {
        console.log(tasks[indexArray[i]].name);
    }
    

    You could use tasks.keys as a shortcut to getting the object indexes, but that is not universally available so you’d have to have an alternate way of doing it anyway.

    Option 2: Output in order of the embedded index tasks[i].index:

    Reading your question again, I realized that there may be another way to interpret your question. Perhaps you meant in index order where it’s the .index data right next to the .name, not the index key on the tasks object. If so, that would take a different routine:

    var sorted = [];
    var i;
    for (i in tasks) {
        sorted.push(tasks[i]);   // collect items from tasks into a sortable array
    }
    sorted.sort(function(a,b) {return(a.index - b.index);});  // sort the array in numeric order by embedded index
    for (i = 0; i < sorted.length; i++) {
        console.log(sorted[i].name);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bidimensional Object array in Java. Some indices aren´t used, because they
I have a new object with a collection of new objects within it on
If you want to use an array of characters/badguys is it better to have
So I have an object and I want to add a bunch of sub-objects
In a Java program, I have an array of objects. Each object has a
Explanation: i have few objects and im declaring them inside $(document).ready(). WHY? because in
I have an application which displays properties dialogs for various GUI-accessible objects. Because there
Suppose I have a Java method that returns a HashMap object. Because a LinkedHashMap
I have an object that is mapped to have a set of objects, very
Suppose I have a design like this: Object GUI has two objects: object aManager

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.