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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:15:43+00:00 2026-06-05T11:15:43+00:00

I have two javascript object with data like this: { data: [ { foo:

  • 0

I have two javascript object with data like this:

{
   "data": [
      {
         "foo": "2388163605_10150954953808606",
         "bar": {
            "xyz": "123",
         },
         "name": {
            "name": [
               {
                  "content": 1,
                  "data": "some text",
                  "id": "2388163605"
               }
            ]
         },
        },
        {
         "not_the_same": "other values",
         "foo": "different",
         "bar": {
            "xyz": "123",
         },
         "name": {
            "name": [
               {
                  "content": 1,
                  "data": "some text",
                  "id": "2388163605"
               }
            ]
         },
        }]
}

Second one:

{
   "data": [
      {
         "foo": "123+09",
         "bar": {
            "xyz": "1adad0",
         },
        },
      }]
}

as you can see, the properties etc vary a bit, and of course the values as well. Also they don’t have the same number of items in them. I’m trying to merge them like this:

$.extend(true,posts, posts_object);

(posts and posts_objects contain the two objects)

I want to merge them into this:

{
   "data": [
      {
         "foo": "2388163605_10150954953808606",
         "bar": {
            "xyz": "123",
         },
         "name": {
            "name": [
               {
                  "content": 1,
                  "data": "some text",
                  "id": "2388163605"
               }
            ]
         },
        },
        {
         "not_the_same": "other values",
         "foo": "different",
         "bar": {
            "xyz": "123",
         },
         "name": {
            "name": [
               {
                  "content": 1,
                  "data": "some text",
                  "id": "2388163605"
               }
            ]
         },
        },
      {
         "foo": "123+09",
         "bar": {
            "xyz": "1adad0",
         },
        },
      }]
}

However, this results in the data from the second object to overwrite the data of the first object. Is there any way to merge them but instead add the items from the second object to the first object?

  • 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-05T11:15:45+00:00Added an answer on June 5, 2026 at 11:15 am

    If by “add the items”, you mean that you want all properties that are in the second object but not in the first to end up being added to the first one, then:

    var tmp;
    $.extend(true, tmp, posts);
    $.extend(true, posts, posts_object);
    $.extend(true, posts, tmp);
    

    might work. It all depends on what copying semantics you want.

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

Sidebar

Related Questions

I'm really new to JavaScript and jQuery. My question is this. I have two
I have a JSON data object and a text/html javascript template written using the
I have two web pages; Foo.aspx and Bar.aspx. Bar.aspx uses jQuery.ajax() to request a
I have created a javascript object var spanglist = { one: q1, two:q2, three:q3,
I have two tables: projects and supplies. Projects have many supplies, like this: has_many
I would like to read geographic data (logitude/latitude) from two sources into one Javascript
I have two ajax functions and use the first one to pass some data
I have an edit page for my object. Because I've divided data in two
I have two JavaScript arrays: var array1 = [Vijendra,Singh]; var array2 = [Singh, Shakya];
I have created two JavaScript files. One file is "validators.js" and the other is

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.