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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:16:09+00:00 2026-06-09T19:16:09+00:00

I miss VB. Maybe that’s sad… I need to make a 3 Dimensional array

  • 0

I miss VB. Maybe that’s sad…

I need to make a “3 Dimensional” array to represent the following data. The data begins as XML and gets parsed into a 2D “Array of arrays” as follows (descriptors added for clarity):

[NodeArray]
    [Node: 0][Year: 2012][Quantity1: 3][Quantity2: 5] [Title: Orange]
    [Node: 1][Year: 2012][Quantity1: 5][Quantity2: 9] [Title: Apple]
    [Node: 2][Year: 2011][Quantity1: 4][Quantity2: 9] [Title: Orange]
    [Node: 3][Year: 2011][Quantity1: 8][Quantity2: 12] [Title: Apple]
    [Node: 4][Year: 2010][Quantity1: 2][Quantity2: 6] [Title: Orange]
    [Node: 5][Year: 2010][Quantity1: 10][Quantity2: 2] [Title: Apple]

I want to parse this 2-D Array into a 3-D Object Array as follows:

[Year Array]
    [2012]
        [Quantity1]: [3],[7]
        [Quantity2]: [5],[9]
        [Title]: [Orange],[Apple]
    [2011]
        [Quantity1]: [4],[8]
        [Quantity2]: [9],[12]
        [Title]: [Orange],[Apple]
    [2010]
        [Quantity1]: [2],[10]
        [Quantity2]: [6],[2]
        [Title]: [Orange],[Apple]

In VB this would have been pretty simple. I would have looked at my original data and redimensioned my array to accomodate the maximum number of entries in each dimension. I would then iterate through the data and load it in…

If the 2012 index = 0 then “Array(0,1,1)” would have returned “9”

I believe this can be done in JSON, but I don’t have enough experience to know how. I hope this question is specific enough to provide some insight on what I am trying to accomplish.

——————EDIT & NEW CODE—————–

I appreciate the answers.

I realize that my fatal flaw at the moment is that I am not building my 2-D array using JSON (despite the fact that my example seems that way). Here is the method I am using to build my 2-D Array:

for(i=0; i<titleArray.length; i++)
{
rowArray[i] = [yearArray[i], titleArray[i],quantityOneArray[i],quantityTwoArray[i]];
}

Because there are always the same number of entries in each array I can reliably use the length of one array to iterate through all associated arrays. I also realize that using “i++” is the middle school way of doing things, so I am open to suggestions on more elegant indexing methods.

But let’s say I want to build this in JSON? I am confident that this is not yet in a JSON format… If it were then I should be able to say “rowArray[i].year” yes?

Thanks again – I am very fortunate to have such an active community.

——————–EDIT2 & NEW CODE——————–

Ok, I think I cracked the JSON nut. I likey! I only had to format the array object a little differently and now I can invoke members of the array by using the .whatever property!

for(i=0; i<titleArray.length; i++) 
{
rowArray[i] = {"year":yearArray[i], "title":titleArray[i],"quantity1":quantityOneArray[i],"quantity2":quantityTwoArray[i]};
console.log("rowArray["+i+"]: " + rowArray[i].year + ", " + rowArray[i].title +", "+rowArray[i].quantity1+", "+rowArray[i].quantity2);
}

Now for the 3-D 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-09T19:16:11+00:00Added an answer on June 9, 2026 at 7:16 pm

    Something like this should do it:

    var year_array = new Array(); // empty array
    for ( node in node_array )
    {
        if ( !year_array.hasOwnProperty(node.year) ) // if year is not in array yet
        {
            year_array[node.year] = new Array(); // create an empty array for it
        }
        year_array[node.year].push({
            "quantity1": node.quantity1,
            "quantity2": node.quantity2,
            "title": node.title,
        });
    }
    

    All this does is go through the 2D array, and puts the values in the 3D array in the format presented. The only bit that’s tricky is the if ( !year_array.hasOwnProperty(node.year) ) block, which initializes each year’s entry the first time it comes up.

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

Sidebar

Related Questions

there is something that I miss about the cc-NUMA architecture and the need to
Can the Spring @Cacheable be configure so that if there is a cache miss
Edit: C# 3.0, net 3.5. I am C++ programmer, so maybe I miss some
I have a program that has a ton of sensors producing data at a
The one thing I really miss in vim is a tiered intellisense support, just
I run next code and I miss somthing, for me it seem OK :
I've been using VS2010RC and I really miss the old help system. Is it
When writing views and nesting views within deeper views I sometimes miss something and
I run into follow problem. Did I miss anything? Association.all().count() 1 Association.all().fetch(1) [Association(**{'server_url': u'server-url',
This is the first time I'm trying random numbers with C (I miss C#).

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.