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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:09:01+00:00 2026-06-06T08:09:01+00:00

I am a bit confused at this point on what is an object, what

  • 0

I am a bit confused at this point on what is an object, what is an array, and what is a JSON. Can someone explain the differences in syntax between the two? and how to add items to each, how to merge each type, and such? I am trying to get this function to take the new information from a JSON object (I think) and merge it with some new information. This information will then be passed to a PHP script to be processed.

Here is the console output:

{"public":{"0":["el29t7","3bmGDy"]}} 
{"public":"[object Object][object Object]"} 

Here is the JS I am using:

/* Helper function to clean up any current data we have stored */
function insertSerializedData(ids, type) {
    // Get anything in the current field
    current_data = $('#changes').val();
    if (!current_data) {
        var data = {};
        data[index++] = ids;
        var final_data = {};
        final_data[type] = data;
        $('#changes').val(JSON.stringify(final_data));
    } else {
        current_data = JSON.parse(current_data);
        var data = {};
        data[index++] = ids;
        // Does the index exist?
        if (type in current_data) {
            var temp_data = current_data[type];
            current_data[type] = temp_data + data;
        } else {
            current_data[type] = data;
        }
        //var extra_data = {};
        //extra_data[type] = data;
        //$.merge(current_data, extra_data);
        $('#changes').val(JSON.stringify(current_data));
    }
    console.log($('#changes').val());
}

The idea is if the key (public, or whatever other ones) doesn’t exist yet, then to make it point to an array of arrays. If it does exist though, then that of array of arrays need to be merged with a new array. For instance:

If I have

{"public":{"0":["el29t7","3bmGDy"]}}  

and I want to merge it with

["aj19vA", "jO71Ba"] 

then final result would be:

{"public":{"0":["el29t7","3bmGDy"], "1":["aj19vA", "jO71Ba"]}} 

How can i go about doing this? 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-06-06T08:09:03+00:00Added an answer on June 6, 2026 at 8:09 am

    Excellent two-part question. Overall, the second question is non-trivial because of the complexity of the first.

    Question 1:

    what is an object, what is an array, and what is a JSON. Can someone
    explain the differences in syntax between the two?

    Question 2:

    and how to add items to each,

    Question 3:

    how to merge each type, and such?

    Answer 1:

    This is a common stumbling point because, JavaScript is more flexible than one might initially expect. Here is the curve.

    In JavaScript everything is an object.

    So here is the code for each:

    //What is an object?
    var obj = { };                
    
    var obj2 = { member:"value", myFunction:function(){} }
    

    Above is an empty object. Then another object with a variable and a function.
    They are called object-literals.

    //What is an array 
    var array1 = [ ] ;     
    
    var array2 = [0,1,2,3,4];
    

    Above is an empty array. Then another array with five Integers.

    Here is the curve that causes confusion.

    //Get elements from each of the prior examples.
    var x = obj2["member"];
    var y = array2[1];
    

    What??? Both Object and Array are accessing values with a bracket?
    This is because both are objects. This turns out to be a nice flexibility for writing advanced code. Arrays are objects.

    //What is JSON?

    JSON stands for JavaScript Object Notiation. As you might have guessed. Everything is an object… It is also an { }; But it is different because – it is used to transfer data to – and – from JavaScript, not actually used (commonly) in JavaScript. It is a file transfer format.

    var JSONObject = {"member":"value"};
    

    The only difference to the prior example is quotes. Essentially we are wrapping the object literal as a string so that it can be transferred to a server, or back, and it can be reinterpreted, very easily. Better than XML – because it does not have to be custom-parsed. Just call, stringify() or ParseJSON(). Google it. The point is… JSON can be converted into an object-literal JS object, and JS object-literals can be converted into JSON, for transfer to a server or a CouchDB database, for example.

    Sorry for the tangent.

    Answer 2:

    How to add an item to each? Here is where the curve stops being a nuisance, and starts being awesome! Because everything is an object, it is all just about the same.

    //Add to an object
    var obj {member1:"stringvalue"}
    obj.member2 = "addme";    //That is it!
    
    //Add to an array
    var array1 [1,2,3,4,5];
    array1[0] = "addme";
    
    array[6] = null;
    
    //We shouldn't mix strings, integers, and nulls in arrays, but this isn't a best-practice tutorial.
    

    Remember the JS object syntax and you may start to see a whole new flexible world of objects open up. But it may take a bit.

    Answer 3: Ah, yeah… how to merge.

    There are seriously (very many) ways to merge two arrays. It depends on exactly what you need. Sorted, Duplicated, Concatenated… there are a few.

    Here is the answer!

    UPDATE: How to make a beautiful multiple dimensional array.

    //Multiple Dimension Array
    var array1 = [1,2,3];
    var array2 = [3,4];
    
    var arraysinArray = [array1,array2]; //That is it!
    

    Here is the curve again, this could be in an object:

    var obj{
       array1:[1,2,3],
       array2:[3,4]
    }
    

    JavaScript is powerful stuff, stick with it; it gets good. : )

    Hope that helps,
    All the best!
    Nash

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

Sidebar

Related Questions

I'm a bit confused with this: can I use PHP variables in a pg
I'm a little bit confused with Html helpers in MVC3. I used this syntax
I am a bit confused about this. If you're building a distributed application, which
I'm a bit confused on this. I have a data table structured like this:
just a bit confused by this code var counter = function() { //... var
I am little bit confused about this statement that I read in a book
This is a bit confused question for those who don't now advanced SQL... However.
I'm a bit confused as to why this isn't working; I assume that because
I am getting myself a bit confused about how to go about this. My
I don't think this question has been asked before. I'm a bit confused on

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.