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

The Archive Base Latest Questions

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

I use an ajax request to return an json encode. Now the return data

  • 0

I use an ajax request to return an json encode.

Now the return data is as follows:

 {"24": {"24":["205", "22", "1", "1", "0", "0"]}};

Which im trying to add to :

///global set
var data = {"24":{"16":["172","22","1","1","0","0"],"15":["160","22","1","1","0","0"]}};

The problem is – my attempt is not adding to the variable. This is my script:

var result = {24: {24:[205, 22, 1, 1, 0, 0]}}; //return data test
var obj = {}
for ( var key in result ){              
if ( result.hasOwnProperty( key ) ) {
    // If the key already exists
    if ( data[ key ] === result[ key ] ) {

        // Empty the temporary object
        obj = {}
        // Loop through the subkeys
        for ( var subkey in result[ key ] ) {              
            if ( result[ key ].hasOwnProperty( [ subkey ] ) ) {

                // Fill in the temporary object
                obj[ subkey ] = result[ key ][ subkey ]
            }
        }

        // Add the new object to the original object
        data[ key ] = obj
    }

    // If the key doesn't exist, do it normally
    else {
        data[ key ] = result[ key ]
       }
    }
}
obj = null

//show change
 console.log(data); 

I did a check on data after this code runs, and there is no new added data. Can any one see the mistake where / why its not inserting the data?

  • 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-02T17:00:05+00:00Added an answer on June 2, 2026 at 5:00 pm

    Try this:

    var data = {"24":{"16":["172","22","1","1","0","0"],"15":["160","22","1","1","0","0"]}};
    var result = {"24": {"24":["205", "22", "1", "1", "0", "0"]}};
    
    function forEach(o,cb){
        for(var i in o){
            if (o.hasOwnProperty(i)){
                cb(i);
            }
        }
    }
    
    forEach(result,function(key){
        if (!data[key]) data[key]={};
        forEach(result[key],function(subkey){
            if (!data[key][subkey]) data[key][subkey]=[];
            forEach(result[key][subkey],function(i){
                data[key][subkey].push(result[key][subkey][i]);
            });
        });
    });
    
    console.log(data);
    

    Demo: http://jsfiddle.net/363uy/

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

Sidebar

Related Questions

I use this pseudo-class to make Ajax request to server: function RequestManager(url, params, success,
For the normal ajax request I use: strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' But this don't work
I am trying to use .ajax() to post a People object to a MVC2
I have many forms that use AJAX (w/ jQuery) for validation and data submission.
I am currently trying to use AJAX in my application via jRails. I am
After trying to format my JSON data by hand in javascript and failing miserably,
Ok so I know long hand ajax but trying to use the jQuery short
I've been trying to make an AJAX request to an external server. I've learned
There is a page: http://renren.com/echo (not real) that will return JSON style data like:
Im ready to start pulling my hair out here. Trying to use jquery ajax

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.