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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:17:33+00:00 2026-06-15T22:17:33+00:00

I have unsorted array with some data and I want to create new array

  • 0

I have unsorted array with some data and I want to create new array width sorted data:

   var gridData = [], i = -1;
        while (i++ < 5) {
                gridData[i] = {
                    "ProjectOwner": ["Corporation1","Corporation2","Corporation3"][i % 2],
                    "ProjectId": i,
                    "ProjectName": String.fromCharCode("A".charCodeAt(0) + i % 3) + (1 + i % 3),
                    "ProjectType": ["Conference","Programming","Research","Conference"][i % 4],
                    "ProjectLeader": "Name1Name2Name3".substr(i % 3 * 5,5) + " " + "Surname1Surname2Surname3".substr(i % 3 * 8,8),
                    "StartDate": new Date(2009 + i % 4 % 2, (i + 3) % 12, 5 + i * 4 % 24).toLocaleDateString(),
                    "EndDate": new Date(2010 + i % 4 % 2, (i + 3) % 12, 5 + i * 4 % 24).toLocaleDateString(),
                    "Summary": "bla bla"
                };
            }

unsorted data looks like object array

and I would like to group it like

//First group by ProjectOwner
Object {Corporation1: Array[3], Corporation2: Array[3]}
   //Second group by ProjectName
   Corporation1: Array[x]
            A1 : Array [x]
                 Object1
                 Object2
                 ...
   Corporation2: Array[x]

and so on…
I have tried array.map and reduce but they don’t seem to work in IE
also I have tried:

$.each(aggregation_content, function(i,aggr) {

    $.each(_newData, function(a, objA) {
        if(i > 0)
            o = _newData[a][aggregation_content[i - 1].cell];
        n = _newData[a][aggregation_content[i].cell];

        if(typeof o == "undefined") //For first row when new Data is empty array
        {
            if(! (n in newData))
                newData[n] = [];
            newData[n].push(objA);
        }
    })})
console.log(newData);

where aggregation_content is

{cell:"ProjectOwner",value:""},{cell:"ProjectName",value:""},{cell:"ProjectLeader",value:""},{cell:"ProjectType",value:""}

and new data is a gridData from the beginning.
this works perfectly for a first aggregation. but the problem is that when I aggregate the array newData I need to use

if(! (n in newData[o]))
    newData[o][n] = [];
 newData[o][n].push(objA);

and that [o] should be a parent of [n] -node.
ok- second group is ok too with that code, but when I want to make 5 inner groups I need to do it like

newData["firstGroup"]["secondGroup"]["thirdGroup"]...[n].push("Some content").

How can this be made programmatically? If I do

newData = newData[o] - no good
or
temp = newData
do something to temp
newData[o] = temp not good eather :'(

I hope I wrote understandable text 😀

____Edited_2012_12_13______________________________________

So the input data is

[Object, Object, Object, Object, Object, Object]
  0: Object
   EndDate: "Monday, April 05, 2010"
   ProjectId: 0
   ProjectLeader: "Name1 Surname1"
   ProjectName: "A1"
   ProjectOwner: "Corporation1"
   ProjectType: "Conference"
   StartDate: "Sunday, April 05, 2009"
   Summary: "bla bla"
   __proto__: Object
 1: Object
   EndDate: "Monday, May 09, 2011"
   ProjectId: 1
   ProjectLeader: "Name2 Surname2"
   ProjectName: "B2"
   ProjectOwner: "Corporation2"
   ProjectType: "Programming"
   StartDate: "Sunday, May 09, 2010"
   Summary: "bla bla"
   __proto__: Object
 2: Object
   ...
 3: Object
    ...
 4: Object
    ...
 5: Object
    ....

And the output data should be something like

Object {Corporation1: Array[3], Corporation2: Array[3]}
 Corporation1: Array[2]
   0: A1:  Array[X]
         0: Object
            EndDate: "Monday, May 09, 2011"
            ProjectId: 1
            ProjectLeader: "Name2 Surname2"
            ProjectName: "A1"
            ProjectOwner: "Corporation2"
            ProjectType: "Programming"
            StartDate: "Sunday, May 09, 2010"
            Summary: "bla bla"
         1: Object
            ...
            ...
   1: B2:  Array[X]
         0: Object
            EndDate: "Monday, May 09, 2011"
            ProjectId: 1
            ProjectLeader: "Name2 Surname2"
            ProjectName: "B2"
            ProjectOwner: "Corporation2"
            ProjectType: "Programming"
            StartDate: "Sunday, May 09, 2010"
            Summary: "bla bla"
         1: Object
            ...
            ...
 Corporation2: Array[2]
   0: A1:  Array[X]
         0: Object
            EndDate: "Monday, May 09, 2011"
            ProjectId: 1
            ProjectLeader: "Name2 Surname2"
            ProjectName: "A1"
            ProjectOwner: "Corporation2"
            ProjectType: "Programming"
            StartDate: "Sunday, May 09, 2010"
            Summary: "bla bla"
         1: Object
            ...
            ...
   1: B2:  Array[X]
         0: Object
            EndDate: "Monday, May 09, 2011"
            ProjectId: 1
            ProjectLeader: "Name2 Surname2"
            ProjectName: "B2"
            ProjectOwner: "Corporation2"
            ProjectType: "Programming"
            StartDate: "Sunday, May 09, 2010"
            Summary: "bla bla"
         1: Object
            ...
            ...

The tree view should be two or more nested nodes.

  • 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-15T22:17:34+00:00Added an answer on June 15, 2026 at 10:17 pm

    I came up with this resoult:

    this.groupBy = function(originalData, aggregation_content) 
        {
            var parentNode,node,i,j,g;
            var newData = {},temp;
            this.array.sortedData = originalData;
            $.each(aggregation_content,function(i,objI){
                $.each(originalData.Items,function(j,objJ){
                    node = originalData.Items[j].GetValue(aggregation_content[i].column).replace(/\W+/gi,"");
                    if(i > 0)
                    {
                        temp = newData;
                        $.each(aggregation_content,function(g,objG){
                            parentNode = originalData.Items[j].GetValue(aggregation_content[g].column).replace(/\W+/gi,"");
                            if(!temp[parentNode])
                            {   
                                temp[parentNode] = [];
                            }
                            temp = temp[parentNode];
                        });
                        temp.push(objJ);
                    }
                    else
                    {
                        if(!newData[node])
                            newData[node] = [];
                    }
                });
            });
            console.log(newData);
            return newData;           
        }
    

    what i do is i make new treeview (multidimencional) array filled with pointers.
    so the output is grouped by aggregation_content.

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

Sidebar

Related Questions

I have an unsorted array and need to extract the longest sequence of sorted
I have unsorted dictionary array and I want to sort it according to artist
I have 1 array of object which contains employees data. its unsorted. I have
I have an unsorted array of objects. I need to know how I can
I have a nested unsorted list and I want to place a click event
I have an unsorted array, what is the best method to remove all the
I have a large unsorted list of items. Some items are important and need
For this problem I have a sorted Array of doubles. I need to be
I have an unsorted Array holding the following IDs: @un_array = ['bar', 'para-3', 'para-2',
So I have an unsorted numeric array int[] anArray = { 1, 5, 2,

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.