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

The Archive Base Latest Questions

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

Hello i was trying to modify an object form the values of another object

  • 0

Hello i was trying to modify an object form the values of another object

this is the one i need to modify :

  y = {name:'m' , age:'28' , g:{m:'n' , f:'y' , k:'n' ,
       other :{x:'f' , y:'m'}} , h:'6' , zip :'12345' } ;

the following object will loop in object y and if it found any matched element , it will change it’s value to match object x

   ​x = {name :'y' , age:'17' , g :{m:'y' ,f:'n'}} ;

CODE

  for(var i in x){
     for(var o in y){
        if(i == o) y[o] = x[i] ; 
            }
      }

when this code runs it change the value of y.(name and age ) it keeps h and zip values as it is which is great

PROBLEM is at g object it only change the value of g.n and g.f and delete the rest of the g object element

jsFiddle example

what i was hoping to get is

  y = {name:'y' , age:'17' , g:{m:'y' , f:'n' , k:'n' ,
   other :{x:'f' , y:'m'}} , h:'6' , zip :'12345' } 

i’m using jquery so if there is any jquery function that will help that’s fine

  • 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-06T21:41:03+00:00Added an answer on June 6, 2026 at 9:41 pm

    You can use jQuery.extend with deep parameter:

    Merge the contents of two or more objects together into the first
    object.

    […]

    The merge performed by $.extend() is not recursive by default; if a
    property of the first object is itself an object or array, it will be
    completely overwritten by a property with the same key in the second
    object. The values are not merged. […] However, by passing true for
    the first function argument, objects will be recursively merged.
    (Passing false for the first argument is not supported.)

    var y = {
        name: 'm',
        age: '28',
        g: {
            m: 'n',
            f: 'y',
            k: 'n',
            other: {
                x: 'f',
                y: 'm'
            }
        },
        h: '6',
        zip: '12345'
    };
    var x = {
        name: 'y',
        age: '17',
        g: {
            m: 'y',
            f: 'n'
        }
    };
    $.extend(true, y, x);
    console.log(y);
    // {
    //     "name": "y",
    //     "age": "17",
    //     "g": {
    //         "m": "y",
    //         "f": "n",
    //         "k": "n",
    //         "other": {
    //             "x": "f",
    //             "y": "m"
    //         }
    //     },
    //     "h": "6",
    //     "zip": "12345"
    // }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to modify this example: http://developer.android.com/resources/tutorials/views/hello-gridview.html But instead of displaying images that
I'm trying to modify the contents of one pointer using another. I want string2
Hello I am trying to modify one of the default files that comes with
Hello I was trying to remove objects from object array that I have and
Hello I'm trying something .. I was reading Jquery traversing documentations some forums, this
**Hello, I'm trying to create an archiver in java. This means that I am
I'm trying to modify some library and I need to store a float value
Hello I'm trying to give each of these button names a uniquely numbered name.
I'm trying to modify an example in this website . I run this example
I am trying to pass some values to another View from the Controller .

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.