Based on your description in the comments, you'd simply do an array concat():

var jsonArray1 = [{'name': "doug", 'id':5}, {'name': "dofug", 'id':23}];
var jsonArray2 = [{'name': "goud", 'id':1}, {'name': "doaaug", 'id':52}];

jsonArray1 = jsonArray1.concat(jsonArray2);

console.log(jsonArray1)
// [{'name': "doug", 'id':5}, {'name': "dofug", 'id':23}, {'name': "goud", 'id':1}, {'name': "doaaug", 'id':52}];

Answer from jacobangel on Stack Overflow
🌐
techtutorialsx
techtutorialsx.wordpress.com › 2020 › 09 › 06 › javascript-merge-json-objects
JavaScript merge JSON objects - techtutorialsx - WordPress.com
January 25, 2025 - Take also in consideration that there are a lot of approaches that can be taken in JavaScript to merge JSON objects: using a loop to iterate over the keys of the objects and assign them to a destination object, using the assign method, using ...
Discussions

javascript - How to combine two JSON objects together - Stack Overflow
JSON is a string representation of data that resembles object syntax. ... @ Rocket Hazmat I agree, two obj which I wanted to be serialized like so, my brain was fried when i was writing this question...Spent few hours on this, it seems that this question was even answered already. I should have used "merge... More on stackoverflow.com
🌐 stackoverflow.com
How to join two JavaScript Objects, without using JQUERY - Stack Overflow
I have two json objects obj1 and obj2, i want to merge them and crete a single json object. The resultant json should have all the values from obj2 and the values from obj1 which is not present in ... More on stackoverflow.com
🌐 stackoverflow.com
Merging two json objects - not so easy
Goal: merge two json objects where ... a json object in glide is super simple by using JSON template column with $merge([$json1, $json2]) But if one of the variables is a basic column which has valid json then it isn’t possible I have tried different approaches One is with JavaScript function ... More on community.glideapps.com
🌐 community.glideapps.com
11
0
July 30, 2024
Best way to merge two objects on a matching key-value pair.
Well in your example, you are attempting to combine two arrays of objects into an object, which assumes that the arrays each contain exactly one object that share a store ID. We can allow for multiple logistics and stores by aiming for an array of combined objects: const storesByStoreId = stores.reduce( (obj, store) => { if (!obj.hasOwnProperty(store.storeId)) { obj[store.storeId] = store; } return obj; }, {} ); const perfectArray = logistics.map(logistic => ({ ...storesByStoreId[logistic.storeId], ...logistic })); The result will look like this: [ { storeId: 409388, ka: 0, country: 'ru', name: 'test', city: 'Moscow', cxw: 1, cx: 1, plz: 22448, logisticsId: 'L5E69E26D8FCAE', logisticsDate: '2020-03-12T07:19:09.000Z' } ] And you can reference that first and only object with perfectArray[0]. More on reddit.com
🌐 r/learnjavascript
2
3
September 15, 2021
🌐
TechTutorialsX
techtutorialsx.com › home › javascript › javascript merge json objects
JavaScript merge JSON objects - techtutorialsx
September 6, 2020 - Take also in consideration that there are a lot of approaches that can be taken in JavaScript to merge JSON objects: using a loop to iterate over the keys of the objects and assign them to a destination object, using the assign method, using ...
🌐
npm
npmjs.com › package › json-merger
json-merger - npm
Merge JSON (or YAML) files and objects with operations like $import $remove $replace $merge and more.
      » npm install json-merger
    
Published: Feb 02, 2025
Version: 3.0.0
🌐
CodingNConcepts
codingnconcepts.com › home › javascript › combine two or more json objects in javascript
Combine Two or more JSON Objects in JavaScript - Coding N Concepts
August 30, 2026 - Combine two or more objects in JavaScript with Object.assign() and the spread operator, including how key collisions are resolved and why nested objects only merge one level deep.
🌐
DevGenius
blog.devgenius.io › combining-json-objects-in-javascript-node-js-abe84f492d0
Combining JSON Objects in JavaScript/Node.js | by Popa Vlad | Dev Genius
March 6, 2025 - // JSON objects to be merged const jsonObj1 = { name: "John", age: 25 }; const jsonObj2 = { city: "New York", hobby: "Coding" }; // Merge JSON objects const mergedJSON = Object.assign({}, jsonObj1, jsonObj2); console.log(mergedJSON);
Find elsewhere
🌐
Research Hubs
researchhubs.com › post › computing › javascript › merge-content-of-objects.html
How to merge content of two or more objects in JavaScript?
var object1 = { apple: 0, banana: ... [{id:1, name: 'xxx' ...}] var json2 = [{id:2, name: 'xyz' ...}] The solution is simply use JavaScript arrayconcat() var finalObj = json1.concat(json2); Dependency injection ·...
Top answer
1 of 6
264

There are couple of different solutions to achieve this:

1 - Native javascript for-in loop:

const result = {};
let key;

for (key in obj1) {
  if(obj1.hasOwnProperty(key)){
    result[key] = obj1[key];
  }
}

for (key in obj2) {
  if(obj2.hasOwnProperty(key)){
    result[key] = obj2[key];
  }
}

2 - Object.keys():

const result = {};

Object.keys(obj1)
  .forEach(key => result[key] = obj1[key]);

Object.keys(obj2)
  .forEach(key => result[key] = obj2[key]);

3 - Object.assign():
(Browser compatibility: Chrome: 45, Firefox (Gecko): 34, Internet Explorer: No support, Edge: (Yes), Opera: 32, Safari: 9)

const result = Object.assign({}, obj1, obj2);

4 - Spread Operator:
Standardised from ECMAScript 2015 (6th Edition, ECMA-262):

Defined in several sections of the specification: Array Initializer, Argument Lists

Using this new syntax you could join/merge different objects into one object like this:

const result = {
  ...obj1,
  ...obj2,
};

5 - jQuery.extend(target, obj1, obj2):

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

const target = {};

$.extend(target, obj1, obj2);

6 - jQuery.extend(true, target, obj1, obj2):

Run a deep merge of the contents of two or more objects together into the target. Passing false for the first argument is not supported.

const target = {};

$.extend(true, target, obj1, obj2);

7 - Lodash _.assignIn(object, [sources]): also named as _.extend:

const result = {};

_.assignIn(result, obj1, obj2);

8 - Lodash _.merge(object, [sources]):

const result = _.merge(obj1, obj2);

There are a couple of important differences between lodash's merge function and Object.assign:

1- Although they both receive any number of objects but lodash's merge apply a deep merge of those objects but Object.assign only merges the first level. For instance:

_.isEqual(_.merge({
  x: {
    y: { key1: 'value1' },
  },
}, {
  x: {
    y: { key2: 'value2' },
  },
}), {
  x: {
    y: {
      key1: 'value1',
      key2: 'value2',
    },
  },
}); // true

BUT:

const result = Object.assign({
  x: {
    y: { key1: 'value1' },
  },
}, {
  x: {
    y: { key2: 'value2' },
  },
});
_.isEqual(result, {
  x: {
    y: {
      key1: 'value1',
      key2: 'value2',
    },
  },
}); // false
// AND
_.isEqual(result, {
  x: {
    y: {
      key2: 'value2',
    },
  },
}); // true

2- Another difference has to do with how Object.assign and _.merge interpret the undefined value:

_.isEqual(_.merge({x: 1}, {x: undefined}), { x: 1 }) // false

BUT:

_.isEqual(Object.assign({x: 1}, {x: undefined}), { x: undefined })// true

Update 1:

When using for in loop in JavaScript, we should be aware of our environment specially the possible prototype changes in the JavaScript types. For instance some of the older JavaScript libraries add new stuff to Array.prototype or even Object.prototype. To safeguard your iterations over from the added stuff we could use object.hasOwnProperty(key) to mke sure the key is actually part of the object you are iterating over.


Update 2:

I updated my answer and added the solution number 4, which is a new JavaScript feature but not completely standardized yet. I am using it with Babeljs which is a compiler for writing next generation JavaScript.


Update 3:
I added the difference between Object.assign and _.merge.

2 of 6
15

WORKING FIDDLE

Simplest Way with Jquery -

var finalObj = $.extend(obj1, obj2);

Without Jquery -

var finalobj={};
for(var _obj in obj1) finalobj[_obj ]=obj1[_obj];
for(var _obj in obj2) finalobj[_obj ]=obj2[_obj];
🌐
Glide Community
community.glideapps.com › ask for help
Merging two json objects - not so easy - Ask for Help - Glide Community
July 30, 2024 - Goal: merge two json objects where one of them is found in a basic text column Merging two json objects created as a json object in glide is super simple by using JSON template column with $merge([$json1, $json2]) But …
🌐
Quora
quora.com › How-can-I-add-two-JSON-objects-into-one-object-JavaScript
How to add two JSON objects into one object JavaScript - Quora
Answer (1 of 4): The Spread syntax could be very helpful here, depending upon exactly what you want to do. [code]let obj1 = { a : ‘aValue’, b : ‘bValue’ }; let obj2 = {c : ‘cValue’, d : ‘dValue’, a : 'obj2AValue' }; let combined = { …obj1, …obj2 }; [/code]Note that if there ...
🌐
Medium
allaboutcode.medium.com › javascript-how-to-merge-2-json-strings-together-and-return-a-string-359455bc48f1
Javascript — How to merge 2 JSON strings together and return a string | by Marika Lam | Medium
June 14, 2022 - We will start our code by defining two JSON strings containing two different objects. These are the objects we will merge. const string1 = `{"name": "Todd","age": 20}`;const string2 = `{"languages": ["Spanish", "Portuguese"],"married": true}`; 2. After defining these JSON strings, we will parse them to JavaScript objects.
🌐
SitePoint
sitepoint.com › blog › javascript › how to merge objects in javascript
How to Merge Objects in JavaScript — SitePoint
November 5, 2024 - Learn how to merge any object in JavaScript with the spread ( ... ) operator, Object.assign() method, and JSON stringify and parse methods.
🌐
Source Code Tester
sourcecodester.com › tutorial › javascript › 15769 › how-merge-two-json-one-array-object-javascript
How to Merge Two JSON into One Array Object in JavaScript | SourceCodester
Learn on how to create How to Merge Two JSON into One Array Object in JavaScript - A simple program that will dynamically merge the two JSON array into one array object. This is a useful program when you are working with an arrays in your working project. JavaScript Free Tutorial.
🌐
YouTube
youtube.com › watch
How to Merge JSON Objects in JavaScript - YouTube
Learn how to effectively merge JSON objects in JavaScript. Follow this comprehensive guide to combine JSON data under specific keys effortlessly!---This vide...
Published: April 7, 2025
Views: 12
🌐
npm
npmjs.com › package › merge-json
merge-json - npm
August 26, 2016 - Merge two JSON Objects into one new Object. Latest version: 0.1.0-b.3, last published: 10 years ago. Start using merge-json in your project by running `npm i merge-json`. There are 64 other projects in the npm registry using merge-json.
      » npm install merge-json
    
Published: Aug 26, 2016
Version: 0.1.0-b.3
🌐
Medium
allaboutcode.medium.com › 3-ways-to-merge-2-json-objects-with-the-same-key-in-javascript-82734fc7807d
3 ways to merge 2 JSON objects with the same key in JavaScript | by Marika Lam | Medium
September 21, 2022 - 3 ways to merge 2 JSON objects with the same key in JavaScript The 3 ways to merge 2 JSON objects are Nested for loop Map and Object.assign concat() 1. Nested for loop
🌐
Colin.js
colinchjs.github.io › 2023-09-24 › 14-32-47-716816-how-to-merge-json-objects-in-javascript
How to merge JSON objects in JavaScript.
September 23, 2023 - Another way to merge JSON objects is by using the Object.assign() method. This method copies the values of all enumerable properties from one or more source objects to a target object.
🌐
Openformatter
openformatter.com › home › blog › json merge: how to combine two json objects safely
JSON Merge: How to Combine Two JSON Objects Safely
March 7, 2026 - Learn how to merge two JSON objects in JavaScript and Python, handle key conflicts, perform deep merges, and avoid common merge mistakes.