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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:07:37+00:00 2026-05-20T16:07:37+00:00

I want to merge two A3 Objects together which contain some of the same

  • 0

I want to merge two A3 Objects together which contain some of the same Keys but different values. I’ve found many posts regarding adding two Objects together but I want to merge the two objects together so if the second object has different values they take priority. I have two Objects below:

    _propsObj =  new Object();
    _propsObj.baseColour = 0x303237;
    _propsObj.animation = false;
    _propsObj.font = "Verdana";
    _propsObj.fontColour = 0xffffff;
    _propsObj.baseFontSize = 14;    

    _propsObj2 =  new Object();
    _propsObj2.animation = true;        
    _propsObj2.fontColour = 0xffffff;
    _propsObj2.baseFontSize = 10;   

My desired ouput Object would accept the new values of the second Object but maintain the values of the first Object :

    _outputObj.baseColour = 0x303237;
    _outputObj.animation = true;
    _outputObj.font = "Verdana";
    _outputObj.fontColour = 0xffffff;
    _outputObj.baseFontSize = 10;   

I wasn’t sure if I should be using Arrray.concat do this or if there is an easier solution? Any help would be appreciated.

  • 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-05-20T16:07:37+00:00Added an answer on May 20, 2026 at 4:07 pm

    the merge method hereunder

        var _propsObj:Object =  new Object();
        _propsObj.baseColour = 0x303237;
        _propsObj.animation = false;
        _propsObj.font = "Verdana";
        _propsObj.fontColour = 0xffffff;
        _propsObj.baseFontSize = 14;    
    
        var _propsObj2:Object =  new Object();
        _propsObj2.animation = true;        
        _propsObj2.fontColour = 0xffffff;
        _propsObj2.baseFontSize = 10;   
            
        var merged:Object = merge( _propsObj, _propsObj2 );
            
        private function merge( obj0:Object, obj1:Object ):Object
        {
            var obj:Object = { };
            for( var p:String in obj0 )
            {
                obj[ p ] = ( obj1[ p ] != null ) ? obj1[ p ] : obj0[ p ];
                trace( p, ' : obj0', obj0[ p ], 'obj1', obj1[ p ], '-> new value = ', obj[ p ] );
            }
            return obj;
        }
        
    

    traces:

    font : obj0 Verdana obj1 undefined -> new value = Verdana

    fontColour : obj0 16777215 obj1 16777215 -> new value = 16777215

    baseColour : obj0 3158583 obj1 undefined -> new value = 3158583

    animation : obj0 false obj1 true -> new value = true

    baseFontSize : obj0 14 obj1 10 -> new value = 10

    the important line is :

    obj[ p ] = ( obj1[ p ] != null ) ? obj1[ p ] : obj0[ p ];
    

    it recursively creates the property on the new Object ‘obj’ and checks if that property is assigned on the 2nd object, if so it assigns the value of the second object to that property, otherwise it falls back to the value of that property on the first object.

    NB: if a value is not set on the first object, it will not be looked up in the second object.

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

Sidebar

Related Questions

I have two or more javascript objects. I want to merge them adding values
I have two objects and I want to merge them: public class Foo {
I'm using classic ASP in my project. I want to merge two XMLs together.
I want to merge all data in two arraylist in c#. Some data in
Assume that you have two IEnumerbale objects. How we can merge them (in some
I want to merge Two HashMaps. I could use map1.putAll(map2); but I don't want
I want to merge two arrays and replace the text with strtr function. I
I want to merge two branches that have been separated for a while and
I want to merge two cells in excel using pyExcelerator , ws.write_merge(r1=0,r2=1,c1=0, c2=0, label='test1',
What i'm trying to do is pretty simple.I want to merge two maps. Say

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.