Before join you need map array

const array = [
    { a: '1', b: '2' },
    { a: '3', b: '4' },
];

const result = array.map(_ => _.a).join(', ');

console.log(result);

Answer from Nikita Madeev on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript - MDN Web Docs
If the array has only one item, then that item will be returned without using the separator. const elements = ["Fire", "Air", "Water"]; console.log(elements.join()); // Expected output: "Fire,Air,Water" console.log(elements.join("")); // Expected output: "FireAirWater" console.log(elements.join("-")); // Expected output: "Fire-Air-Water" ... A string to separate each pair of adjacent elements of the array.
🌐
TutorialsPoint
tutorialspoint.com › typescript › typescript_array_join.htm
TypeScript - Array join()
join() method joins all the elements of an array into a string. separator − Specifies a string to separate each element of the array. If omitted, the array elements are separated with a comma.
Discussions

Help with handling JSON array of objects (merge two arrays)
Split things up a bit and type your objects to make the logic easier to follow (this is off the top of my head, may not be 100% correct): interface Pipe { OD: number; SCH: {SCH40: number; SCH80: number}; Area?: number; // I think? } const getArea = (pipe: Pipe, sch: 'SCH40' | 'SCH80') => { return }; // Add an 'Area' property to each 'Pipe' object const pipesWithArea: Pipe[] = this.Pipesizes.map(x => ({...x, Area: getArea(x, this.selectedSCH)})); return pipesWithArea.find(x => x.Area >= this.OutsideNumber); More on reddit.com
🌐 r/typescript
14
14
April 25, 2020
merge two object arrays with Angular 2 and TypeScript? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I have gone across the JavaScript questions on this topic, this question is specifically about Angular2 with TypeScript. What I am trying to do is to concatenate the json objects to an array. More on stackoverflow.com
🌐 stackoverflow.com
Perform .join on value in array of objects
Despite the code being slightly less clean/clear. It is a much more efficient than piping the map function to a join. The reason for this is because Array.map has to loop over each element to return a new array with all of the names of the object in the array. More on stackoverflow.com
🌐 stackoverflow.com
jquery - Merge two json/javascript arrays in to one array - Stack Overflow
its dynamic. so I cant use index. I need a function which can merge n number of objects into final object. Murtaza Khursheed Hussain – Murtaza Khursheed Hussain · 2012-04-30 13:53:58 +00:00 Commented Apr 30, 2012 at 13:53 ... Those aren't JSON objects, just arrays. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Codemzy
codemzy.com › blog › array-join-object-property
Using Array join() on an object property - Codemzy's Blog
May 30, 2023 - If you did want to join your array of objects, you can turn the objects into strings first using Array.map() on the array, and JSON.stringify() on the objects.
🌐
Reddit
reddit.com › r/typescript › help with handling json array of objects (merge two arrays)
r/typescript on Reddit: Help with handling JSON array of objects (merge two arrays)
April 25, 2020 -

I have a json array of Objects and need to pick a corresponding object in that array according to some calculations.

My json have a following structure: {"OD": number, "SCH" {"SCH40": number, "SCH80": number}}

I need to do some math with OD and SCH numbers, compare it with an outside number and find corresponding value for OD key.

I can get a new array (of numbers I compare the outside number with):

this.Pipeareas = this.Pipesizes.map (x => Math.pow((x.OD - 2 * x.SCH[this.selectedSCH])/2000,2) * Math.PI);

How to merge existing and new arrays?

I tried (this add extra existing array and new object to new array (not key:value pair))

this.Pipeareas = {...this.Pipesizes, Area: this.Pipesizes.map (x => Math.pow((x.OD - 2 * x.SCH[this.selectedSCH])/2000,2) * Math.PI) }

and (this adds new key "Area" to each object but the value is full array, not corresponding numbers from new array)

this.Pipesizes.map (x => x.Area = this.Pipesizes.map (x => Math.pow((x.OD - 2 * x.SCH[this.selectedSCH])/2000,2) * Math.PI))

The result should be like:

return this.Pipeareas.find(x => x >= this.OutsideNumber);

🌐
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 - const jsonObj1 = { name: "John", age: 25 }; const jsonObj2 = { city: "New York", hobby: "Coding" }; const mergedJSON = { ...jsonObj1, ...jsonObj2 }; console.log(mergedJSON); This method has the same effect as using Object.assign(). ... Vlad is an IT enthusiast with experience in multiple areas of Technology.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › typescript-array-join-method
TypeScript Array join() Method - GeeksforGeeks
July 12, 2024 - The Array.join() method in TypeScript is a built-in function used to join all the elements of an array into a single string.
🌐
DEV Community
dev.to › fullstackchris › advanced-typescript-a-generic-function-to-merge-object-arrays-18ja
Advanced TypeScript: A Generic Function to Merge Object Arrays - DEV Community
December 9, 2021 - You could explicitly write key / value assignments for the keys that you want to update... or you can leverage JavaScript's built in Object.assign function and TypeScript's generic capabilities to only write one such function for all merging actions you need across your entire app! 😄 · For example, in ReduxPlate, I have two types, IFile, and IEditorSettings: ... IEditorSettings extends IFile and has just one additional property: isActive. When visitors click the "Generate!" button on the MVP page, the response from the server returns an array of objects of type IFile instead of IEditorSettings, since the server is not concerned with the isActive property.
🌐
TutorialsPoint
tutorialspoint.com › typescript › typescript_array_concat.htm
TypeScript - Array concat()
concat() method returns a new array comprised of this array joined with two or more arrays. valueN − Arrays and/or values to concatenate to the resulting array. Returns a new array.
🌐
CodeProject
codeproject.com › Questions › 5332641 › How-can-I-combine-some-arrays-to-create-a-unified
How can I combine some arrays to create a unified JSON in typescript / javascript - CodeProject
May 19, 2022 - Internet of Things · C / C++ / MFC> ATL / WTL / STL · Managed C++/CLI · C# Free Tools · Objective-C and Swift · Database · Hardware & Devices> System Admin · Hosting and Servers · Java · Linux Programming · Python · .NET (Core and Framework) Android ·
Top answer
1 of 10
123

You want the concat method.

var finalObj = json1.concat(json2);
2 of 10
39

Upon first appearance, the word "merg" leads one to think you need to use .extend, which is the proper jQuery way to "merge" JSON objects. However, $.extend(true, {}, json1, json2); will cause all values sharing the same key name to be overridden by the latest supplied in the params. As review of your question shows, this is undesired.

What you seek is a simple javascript function known as .concat. Which would work like:

var finalObj = json1.concat(json2);

While this is not a native jQuery function, you could easily add it to the jQuery library for simple future use as follows:

;(function($) {
    if (!$.concat) {
        $.extend({
            concat: function() {
                return Array.prototype.concat.apply([], arguments);
            }
        });
    }
})(jQuery);

And then recall it as desired like:

var finalObj = $.concat(json1, json2);

You can also use it for multiple array objects of this type with a like:

var finalObj = $.concat(json1, json2, json3, json4, json5, ....);

And if you really want it jQuery style and very short and sweet (aka minified)

;(function(a){a.concat||a.extend({concat:function(){return Array.prototype.concat.apply([],arguments);}})})(jQuery);

;(function($){$.concat||$.extend({concat:function(){return Array.prototype.concat.apply([],arguments);}})})(jQuery);

$(function() {
    var json1 = [{id:1, name: 'xxx'}],
        json2 = [{id:2, name: 'xyz'}],
        json3 = [{id:3, name: 'xyy'}],
        json4 = [{id:4, name: 'xzy'}],
        json5 = [{id:5, name: 'zxy'}];
    
    console.log(Array(10).join('-')+'(json1, json2, json3)'+Array(10).join('-'));
    console.log($.concat(json1, json2, json3));
    console.log(Array(10).join('-')+'(json1, json2, json3, json4, json5)'+Array(10).join('-'));
    console.log($.concat(json1, json2, json3, json4, json5));
    console.log(Array(10).join('-')+'(json4, json1, json2, json5)'+Array(10).join('-'));
    console.log($.concat(json4, json1, json2, json5));
});
center { padding: 3em; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<center>See Console Log</center>

jsFiddle

🌐
EyeHunts
tutorial.eyehunts.com › home › javascript join the array of objects | example code
JavaScript join the array of objects | Example code
August 19, 2022 - Code snip for join object values. console.log([ {name: "Joe", age: 22}, {name: "Kevin", age: 24}, {name: "Peter", age: 21} ].map(function(elem){ return elem.name; }).join(",")); In modern JavaScript, this will not perform with the join method only on the name attribute, to achieve the same output as before. console.log([ {name: "Joe", age: 22}, {name: "Kevin", age: 24}, {name: "Peter", age: 21} ].map(e => e.name).join(","));
🌐
Paige Niedringhaus
paigeniedringhaus.com › merge javascript objects in an array with different defined properties
Merge JavaScript Objects in an Array with Different Defined Properties | Paige Niedringhaus
June 6, 2022 - I needed to combine all the properties of objects that shared a common key along with their defined values into a new single object. And to make it just a smidge more difficult I needed it to work in TypeScript. 😅 · So today, I'll show you how to use JavaScript's reduce() function to merge two (or more) objects in an array with different defined properties.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-join-array-of-objects
Mastering Array Join in TypeScript: Joining Arrays of Objects
Another approach is to use the ... 'Alice, Bob, Charlie' If you need to join multiple arrays of objects together, you can use methods like concat() or the spread operator to merge them....