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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:42:19+00:00 2026-06-04T12:42:19+00:00

I have an object with depth at most 3: OBJ.T.V.E={…} T and V are

  • 0

I have an object with depth at most 3:

OBJ.T.V.E={...}

T and V are integers (like in OBJ[0][1][‘String’]={…} )
so a typical structure could be:

OBJ[0][0]['S1']={..}
OBJ[0][0]['S2']={..}
OBJ[0][1]['S1']={..}
OBJ[0][2]['S1']={..}

I want to rearrange and get somehow this:

OBJNEW['S1'][0][0]={...}

which would have the same value as in OBJ[0][0]['S1']

I’m struggling for hours with no luck. Any ideas? Jquery code is also welcome.

EDIT:
Right now I tried creating an array of objects like that:

OBJ2=[];
$.each(OBJ, function(name, value) {
  $(value).each(OBJ, function(name1, value1) {
    OBJ2[name1]=[];
    $(value1).each(OBJ, function(name2, value2) {
      OBJ2[name1][name2]={};
      OBJ2[name1][name2]['S1']={};
    })
  })

But this step fails since each …[‘S1’] assignment overwrites the previous object (e.g. S2).

Please ignore any typos, I have just recreated the logic.

  • 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-04T12:42:21+00:00Added an answer on June 4, 2026 at 12:42 pm

    This should get you pretty far, unless I misunderstood.

    function flipObject(o) {
      var i1, i2, i3, result = {};
    
      for ( i1 in o ) {
        if ( o.hasOwnProperty(i1) ) {
          for ( i2 in o[i1] ) {
            if ( o[i1].hasOwnProperty(i2) ) {
              for ( i3 in o[i1][i2] ) {
                if ( o[i1][i2].hasOwnProperty(i3) ) {
                  if ( !(i3 in result) ) result[i3] = {};
                  if ( !(i1 in result[i3]) ) result[i3][i1] = {};
                  result[i3][i1][i2] = o[i1][i2][i3];
                }
              }
            }
          }
        }
      }
      return result;
    }
    

    It turns

    {
        "0": {
            "0": {
                "s1": "s1.0.0",
                "s2": "s2.0.0"
            },
            "1": {
                "s1": "s1.0.1",
                "s2": "s2.0.1"
            }
        },
        "1": {
            "0": {
                "s1": "s1.1.0",
                "s2": "s2.1.0"
            },
            "1": {
                "s1": "s1.1.1",
                "s2": "s2.1.1"
            }
        }
    }
    

    into

    {
        "s1": {
            "0": {
                "0": "s1.0.0",
                "1": "s1.0.1"
            },
            "1": {
                "0": "s1.1.0",
                "1": "s1.1.1"
            }
        },
        "s2": {
            "0": {
                "0": "s2.0.0",
                "1": "s2.0.1"
            },
            "1": {
                "0": "s2.1.0",
                "1": "s2.1.1"
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a nested object structure like: var o = { a: {
I have an object of type FSharpOption, but I don't know it's depth. It
I have 2 object. In different depths of MovieClip. I would like to know
I have an object for which I'd like to track the number of threads
I have an object for which I want to generate a unique hash (override
Lets say i have a Shape object that has a constructor like this: Shape(
I have a survey that's stored in a large object graph of variable depth,
I have the a class Foo like this: class Foo { public int id{get;set;}
I have an FBO object with a color and depth attachment which I render
I have an XDocument object. I want to query for elements with a particular

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.