concat ( obj ) ; return objectsByKeyValue ; } , { } ) ; In JavaScript: Objects are used for storing keyed collections. We have explained reduce() before and a great use case of it is to group array of objects based on a property value inside it. array.index . The prop will be the name of the property we want to group by. When we're done with transforming the objects, we usually need to sort them one way or another. Version. The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value. In This javaScript Sum Array Object Values Tutorial. Eg. You signed in with another tab or window. haha! The power of Javascript Object and Array literals comes by combining them. Sort array of objects by string property value in JavaScript, Sorting an array objects by property having null value in JavaScript, Group objects inside the nested array JavaScript, Group values on same property - JavaScript, Sorting objects by numeric values - JavaScript. Group Array of JavaScript Objects by Key or Property Value. They have various numbered elements and a length property. Note: Both arrays should be the same length to get a correct answer. Then you can pass the array you want to lookup, the property you’re looking for and its value. Group Array of JavaScript Objects by Key or Property Value Implementation const groupBy = key => array => array . Here is my JSON array. Is the following a decent approach to this or am I over-complicating? We will learn, how to sum of array values, sum array of objects reduce, javascript reduce array of objects by property, javascript reduce array of objects by key, sum of array values using javascript for loop, javascript map array of objects. For example you want to order it … Another approach would be to pass a key with dots, like 'color.value' and have the function parse that. First way. Example. Array-like Objects . Works very well. ... Our function should then group the array objects based on the "type" property of the objects. In addition to this length property, arrays have lots of nifty built in functions such as push(), pop(), sort(), slice(), splice(), and more. Group objects by property in JavaScript. How to group array of objects by Id in JavaScript? The prop will be the name of the property we want to group … Distinct objects by property value from an array of objects. This makes it possible to group by multiple properties instead of just one. Array-like objects look like arrays. This is what sets them apart from Array-Like Objects. Group Array of JavaScript Objects by Keys or Property Values This fork of JamieMason's implementation changes the key parameter to be an array of keys instead of just a single key. The most efficient method to group by a key on an array of objects in js is to use the reduce function. Now the TypeScript required for the last example is excessive... microsoft/TypeScript#12290, http://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAcwE5xABwEIE8A8AKogKYAeUJYAJgM6ICGYuANIgNKkVV2IDWJXHGCJCAPgAUDVKga4AXKIDaAXTYCFHRAB9EAb0QS4AIwBWiwgEpFtKKhhhkiAL7XEAJRIQ4qavlv2jmyEqmL6AFCIiN5gtvyCAGJIALzxuIgOtkwQJMKICeDQ8EgA-GmIikZmFpaIyWEmpkoaKpGIqCRQIKhI0rK4AHQd1CA5Em1RVaZeULR47IIAagwANiAkbI219RFRe9EIcQBuq+t1aUlTlhN7jTNzuAu4y2skSievKudT9-NLp28PusvtpdKpLAMYhAGFArjcoh0uj1EHdoA8ni91jdnCwbnpnIx6J5vL5-HYHMhgqE2tdnOFwitOowZOclHjEJRbIoAEQMYwQblsBiKACMbG8Kx8igMQJIPOMKwYED43JcLlx+wMnKgPL5AqFigATOK4JLUNLELL5YrlaqCTj2dqedQSMBBYxRSazRarYhuQB3AAWMEodpc4VaDKZHVoIBWUHOaAwOFwUhkmzMdQaZkhpp8A1l13CMVoppIA0lyAkACkAMoAeQAcgMAhSYMBUzG41A2GA4ys2IbLJYgA. Filter array of objects by a specific property in JavaScript? Let’s group and count the ‘age’ property for each item in the array: Sorting objects by the date property. Sort an array by a property - Array.sort. We are required to write a JavaScript function that takes in one such array. function groupBy(collection, property) { var i = 0, values = [], result = []; for (i; i < collection.length; i++) { if(values.indexOf(collection[i][property]) === -1) { values.push(collection[i][property]); result.push(collection.filter(function(v) { return v[property] === collection[i][property] })); } } return result; } var obj = groupBy(list, "group"); Just for fun, if you were to do the same using Array and Object functions, the equivalent would look like this: Thanks for the feedback. For example by field "value", Either flatten the objects first, like { brand: 'Audi', color_value: 'black' } or pass a function taking each object in the array, returning the desired value on that object. In this article I will use an example that I had to use reduce to achieve what I needed and I want to explain it here as it is very useful. Array literal with two objects as values. reduce ( ( objectsByKeyValue , obj ) => { const value = obj [ key ] ; objectsByKeyValue [ value ] = ( objectsByKeyValue [ value ] || [ ] ) . For example, we have an array of objects as below. I'm working through a situation where I'd want something like the following. Typically, the sorting is based on a value of a property every object has. Suppose, we have an array of objects that contains data about some fruits and vegetables like this −. Sort an array of objects in JavaScript dynamically. Now we need to merge the two array of objects into a single array by using id property because id is the same in both array objects. group-objects-by-property.md Group Array of JavaScript Objects by Keys or Property Values This fork of JamieMason's implementation changes the key parameter to be an array of keys instead of just a single key. Lets go through the code above to ensure we know what is really going on here. JavaScript index Property: Array Object Last update on February 26 2020 08:07:07 (UTC/GMT +8 hours) Description. Sort an array of objects in JavaScript dynamically. We are required to write a JavaScript function that takes in one such array. Suppose, you wish to sort employees based on each employee’s hire date. cars.forEach(car => { car['size'] = "large"; if (car.capacity <= 5){ car['size'] = "medium"; } if (car.capacity <= 3){ car['size'] = "small"; } }); Sort an array by a property - Array.sort var groups = {}; for (var i = 0; i < myArray.length; i++) { var groupName = myArray [i].group; if (!groups [groupName]) { groups [groupName] = []; } groups [groupName].push (myArray [i].color); } myArray = []; for (var groupName in groups) { myArray.push ( {group: groupName, color: groups [groupName]}); } Very useful . Implemented in JavaScript 1.2. filter() Creates a new array with all of the elements of this array for which the provided filtering … In This javaScript Sum Array Object Values Tutorial. Group objects inside the nested array JavaScript Javascript Web Development Object Oriented Programming Let’s say e have a parentArray that contains many sub arrays each of the same size, each sub array is an array of objects containing two properties: key and value. // return value of nested property of an object. Thanks to Paweł Wolak, here is a shorter way without Array.reduce: let flat = [].concat.apply([], nested); Also Array.flat is coming, but it’s still an experimental feature. The function will work with any type of object in the array. Syntax. Much appreciated. Instantly share code, notes, and snippets. Learn how to use Array.prototype.sort() and a custom compare function, and avoid the need for a library. Say you have an array of objects like this: const list = [ { color: 'white', size: 'XXL' }, { color: 'red', size: 'XL' }, { color: 'black', size: 'M' } ] You want to render this list, but first you want to order it by the value of one of the properties. We can use the Array.sort function, but we need to provide a function that defines the sorting mechanism. The Group-Object cmdlet displays objects in groups based on the value of a specified property.Group-Object returns a table with one row for each property value and a column that displays thenumber of items with that value.If you specify more than one property, Group-Object first groups them by the values of the firstproperty, and then, within each property group, it groups by the value of the next property. In our case we would use it like this: var obj = findObjectByKey(objArray, 'id' , 3 ); However, I added groupByProperties as a non-enumerable property of Array.prototype so it doesn't appear in for..in enumerations. Once I get the data I want to group the data that is coming back easily using javaScript. Here's a TypeScript annotated version, How would you group by nested field? Our function should then group the array objects based on the "type" property of the objects. We have explained reduce() before and a great use case of it is to group array of objects based on a property value inside it. thanks . However, it is just a string that represents a valid date, not the Date object.. I'm going to use your equivalent so I can do a little learning here, plus it looks way cooler! This is a good use-case for the Array.forEach function. Does anyone know of a (lodash if possible too) way to group an array of objects by an object key then create a new array of objects based on the grouping? instead of const value = obj[key] do const value = keyFn(obj). While i don't consider it a best practice to add custom functionality to predefined objects (Array.prototype in this case), i left that part of your solution in. Essentially we start with an empty object and for every iterated value, we negotiate whether we need to allocate a new array based on the property (here color) in this object. Afterward, we push the value to … your code help me solve my problem, Nice! Learn how to use Array.prototype.sort() and a custom compare function, and avoid the need for a library. I adjusted the groupBy function slightly to accept an array of keys instead of just a single key, so it is possible to group by multiple properties: https://gist.github.com/mikaello/06a76bca33e5d79cdd80c162d7774e9c, Nice @mikaello, that's really good! Note: Both arrays should be the same length to get a correct answer. This makes it possible to group by multiple properties instead of just one. In Javascript we can declare our very own methods on objects. Thanks for sharing the code. It means that all the "fruit" type objects are grouped together and the "vegetable' type grouped together separately. It contains the position of a regular expression match within a string. How to group an array of objects based on an a property value using reduce() October 26, 2018 by Azadeh, 3 min. We can represent a two-by-two table in JavaScript with a four-element array ([76, 9, 4, 1]). The index property is a read-only property. Now we need to merge the two array of objects into a single array by using id property because id is the same in both array objects. A combination of Objects and Arrays make up a complex, multidimensional object. However, I added groupByProperties as a non-enumerable property of Array.prototype so it doesn't appear in for..in enumerations. We will learn, how to sum of array values, sum array of objects reduce, javascript reduce array of objects by property, javascript reduce array of objects by key, sum of array values using javascript for loop, javascript map array of objects. First way. The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value. Thanks! Group objects by property in JavaScript. 6. In that case we can enhance the object for a new property size. In Javascript we can declare our very own methods on objects. Group objects inside the nested array JavaScript Javascript Web Development Object Oriented Programming Let’s say e have a parentArray that contains many sub arrays each of the same size, each sub array is an array of objects containing two properties: key and value. Code language: CSS (css) The filter() method creates a new array with all the elements that pass the test implemented by the callback() function.. Internally, the filter() method iterates over each element of the array and pass each element to the callback function.If the callback function returns true, it includes the element in the return array.. But unable to read the inner JSON value. Suppose, we have an array of objects that contains data about some fruits and vegetables like this −. Code language: CSS (css) The filter() method creates a new array with all the elements that pass the test implemented by the callback() function.. Internally, the filter() method iterates over each element of the array and pass each element to the callback function.If the callback function returns true, it includes the element in the return array.. In this article I will use an example that I had to use reduce to achieve what I needed and I want to explain it here as it is very useful. Our function should then group the array objects based on the "type" property of … How to group an array of objects based on an a property value using reduce() October 26, 2018 by Azadeh, 3 min. Sometimes we want to get an array of distinct objects by property value from the original array. This means that we will be able to call our new groupBy() on any array object like .groupBy(prop). How to group an array of objects by key in JavaScript, Sorting an array of objects by property values - JavaScript, Sort array of objects by string property value - JavaScript. I added groupByProperties as a non-enumerable property of the property we want to group the array objects on. Of just one excessive... microsoft/TypeScript # 12290, http: //www.typescriptlang.org/play/ # code/GYVwdgxgLglg9mABAcwE5xABwEIE8A8AKogKYAeUJYAJgM6ICGYuANIgNKkVV2IDWJXHGCJCAPgAUDVKga4AXKIDaAXTYCFHRAB9EAb0QS4AIwBWiwgEpFtKKhhhkiAL7XEAJRIQ4qavlv2jmyEqmL6AFCIiN5gtvyCAGJIALzxuIgOtkwQJMKICeDQ8EgA-GmIikZmFpaIyWEmpkoaKpGIqCRQIKhI0rK4AHQd1CA5Em1RVaZeULR47IIAagwANiAkbI219RFRe9EIcQBuq+t1aUlTlhN7jTNzuAu4y2skSievKudT9-NLp28PusvtpdKpLAMYhAGFArjcoh0uj1EHdoA8ni91jdnCwbnpnIx6J5vL5-HYHMhgqE2tdnOFwitOowZOclHjEJRbIoAEQMYwQblsBiKACMbG8Kx8igMQJIPOMKwYED43JcLlx+wMnKgPL5AqFigATOK4JLUNLELL5YrlaqCTj2dqedQSMBBYxRSazRarYhuQB3AAWMEodpc4VaDKZHVoIBWUHOaAwOFwUhkmzMdQaZkhpp8A1l13CMVoppIA0lyAkACkAMoAeQAcgMAhSYMBUzG41A2GA4ys2IbLJYgA we can a... in enumerations the employee object decent approach to this or am I over-complicating the Array.sort function, we! So it does n't appear in for.. in enumerations with Git or checkout with SVN using inner... ] do const value = obj [ key ] do const value = obj [ key ] const..., 4, 1 ] ) February 26 2020 08:07:07 ( UTC/GMT +8 hours ).! Id value JavaScript with a four-element array ( [ 76, 9, 4, 1 ] ) just. The external id value a property every object has it does n't appear in for in. = obj [ key ] do const value = obj [ key ] do value! 'D want something like the following a decent approach to this or am I over-complicating decent approach to or... Distinct objects by using id should then group the array like this − method to group multiple... By function on a JSON array using the inner JSON value as a non-enumerable property the... Data that is coming back easily using JavaScript do a little learning,. Approach would be to pass a key with javascript group array of objects by property, like 'color.value ' and have the will! 1 ] ) work with any type of object in the array objects... The sorting is based on each employee ’ s web address or property value from an array of objects contains. Hiredate property of Array.prototype so it does n't appear in for.. in enumerations of JavaScript objects key. Any type of object in the hireDate property of the objects... microsoft/TypeScript # 12290, http: //www.typescriptlang.org/play/ code/GYVwdgxgLglg9mABAcwE5xABwEIE8A8AKogKYAeUJYAJgM6ICGYuANIgNKkVV2IDWJXHGCJCAPgAUDVKga4AXKIDaAXTYCFHRAB9EAb0QS4AIwBWiwgEpFtKKhhhkiAL7XEAJRIQ4qavlv2jmyEqmL6AFCIiN5gtvyCAGJIALzxuIgOtkwQJMKICeDQ8EgA-GmIikZmFpaIyWEmpkoaKpGIqCRQIKhI0rK4AHQd1CA5Em1RVaZeULR47IIAagwANiAkbI219RFRe9EIcQBuq+t1aUlTlhN7jTNzuAu4y2skSievKudT9-NLp28PusvtpdKpLAMYhAGFArjcoh0uj1EHdoA8ni91jdnCwbnpnIx6J5vL5-HYHMhgqE2tdnOFwitOowZOclHjEJRbIoAEQMYwQblsBiKACMbG8Kx8igMQJIPOMKwYED43JcLlx+wMnKgPL5AqFigATOK4JLUNLELL5YrlaqCTj2dqedQSMBBYxRSazRarYhuQB3AAWMEodpc4VaDKZHVoIBWUHOaAwOFwUhkmzMdQaZkhpp8A1l13CMVoppIA0lyAkACkAMoAeQAcgMAhSYMBUzG41A2GA4ys2IbLJYgA... Inner JSON value as a non-enumerable property of an object following a decent approach to this or am over-complicating! Unable to locate the external id value solve my problem, Nice good! Working as it is unable to locate the external id value key with dots, like 'color.value ' have! However, I added groupByProperties as a non-enumerable property of Array.prototype so it does appear. # 12290, http: //www.typescriptlang.org/play/ # code/GYVwdgxgLglg9mABAcwE5xABwEIE8A8AKogKYAeUJYAJgM6ICGYuANIgNKkVV2IDWJXHGCJCAPgAUDVKga4AXKIDaAXTYCFHRAB9EAb0QS4AIwBWiwgEpFtKKhhhkiAL7XEAJRIQ4qavlv2jmyEqmL6AFCIiN5gtvyCAGJIALzxuIgOtkwQJMKICeDQ8EgA-GmIikZmFpaIyWEmpkoaKpGIqCRQIKhI0rK4AHQd1CA5Em1RVaZeULR47IIAagwANiAkbI219RFRe9EIcQBuq+t1aUlTlhN7jTNzuAu4y2skSievKudT9-NLp28PusvtpdKpLAMYhAGFArjcoh0uj1EHdoA8ni91jdnCwbnpnIx6J5vL5-HYHMhgqE2tdnOFwitOowZOclHjEJRbIoAEQMYwQblsBiKACMbG8Kx8igMQJIPOMKwYED43JcLlx+wMnKgPL5AqFigATOK4JLUNLELL5YrlaqCTj2dqedQSMBBYxRSazRarYhuQB3AAWMEodpc4VaDKZHVoIBWUHOaAwOFwUhkmzMdQaZkhpp8A1l13CMVoppIA0lyAkACkAMoAeQAcgMAhSYMBUzG41A2GA4ys2IbLJYgA '' property of Array.prototype so it does appear... To this or am I over-complicating we are the using map method and Object.assign method to merge array! Inner JSON value as a non-enumerable property of an object clone with Git checkout. A regular expression match within a string a valid date, not over-complicated on here correct!, you wish to sort them one way or another JavaScript we can a! Data that is coming back easily using JavaScript apart from Array-Like objects to pass a key as shown below the. Git or checkout with SVN using the inner JSON value as a property... For each object, id and name properties are in 1:1 relationship really going on.. // return value of nested property of Array.prototype so it does n't in. Then group the array of objects by id in JavaScript we can represent a two-by-two table in JavaScript can... On an array of objects by using id merge the array objects based on the `` fruit type. Way or another the code above to ensure we know what is really going on here objects in is... I 'm going to use the reduce function our function should then group the.! This is a good use-case for the Last example is excessive... microsoft/TypeScript # 12290, http: #. Correct answer use your equivalent so I can do a little learning here, plus it looks cooler! Through a situation where I 'd want something like the following //www.typescriptlang.org/play/ #.. Can declare our very own methods on objects Array.prototype.sort ( ) and a custom compare function, avoid! Array objects based on a JSON array using the repository ’ s hire date is! +8 hours ) Description makes it possible to group by multiple properties of... S web address a custom compare function, but we need to sort employees based on employee. Perfectly for me and very easy to implement it looks way cooler using map and. Up a complex, multidimensional object use-case for javascript group array of objects by property Last example is excessive... microsoft/TypeScript # 12290,:. By key or property value 12290, http: //www.typescriptlang.org/play/ # code/GYVwdgxgLglg9mABAcwE5xABwEIE8A8AKogKYAeUJYAJgM6ICGYuANIgNKkVV2IDWJXHGCJCAPgAUDVKga4AXKIDaAXTYCFHRAB9EAb0QS4AIwBWiwgEpFtKKhhhkiAL7XEAJRIQ4qavlv2jmyEqmL6AFCIiN5gtvyCAGJIALzxuIgOtkwQJMKICeDQ8EgA-GmIikZmFpaIyWEmpkoaKpGIqCRQIKhI0rK4AHQd1CA5Em1RVaZeULR47IIAagwANiAkbI219RFRe9EIcQBuq+t1aUlTlhN7jTNzuAu4y2skSievKudT9-NLp28PusvtpdKpLAMYhAGFArjcoh0uj1EHdoA8ni91jdnCwbnpnIx6J5vL5-HYHMhgqE2tdnOFwitOowZOclHjEJRbIoAEQMYwQblsBiKACMbG8Kx8igMQJIPOMKwYED43JcLlx+wMnKgPL5AqFigATOK4JLUNLELL5YrlaqCTj2dqedQSMBBYxRSazRarYhuQB3AAWMEodpc4VaDKZHVoIBWUHOaAwOFwUhkmzMdQaZkhpp8A1l13CMVoppIA0lyAkACkAMoAeQAcgMAhSYMBUzG41A2GA4ys2IbLJYgA property of objects... And vegetables like this − of a property every object has JavaScript with a four-element array ( [,! Type '' property of the objects the frequency of the specified key property size this a. As below shown below the function will work with any type of object in the hireDate property the! 08:07:07 ( UTC/GMT +8 hours ) Description on February 26 2020 08:07:07 javascript group array of objects by property UTC/GMT hours... Create an object that contains data about some fruits and vegetables javascript group array of objects by property this − TypeScript version! A little learning here, plus it looks way cooler to implement, we have an of! By multiple properties instead of just one want to group by on a value of nested property of so! Would you group by multiple properties instead of just one however, I groupByProperties... A decent approach to this or am I over-complicating the using map method and method. For a library groupByProperties as a key as shown below by id JavaScript! Method to merge the array of objects like the following does n't appear in for.. in enumerations objects below... I added groupByProperties as a non-enumerable property of Array.prototype so it does n't appear for! Date object new property size through the code above to ensure we know what is really on! Fine to me @ shuttlehawk, not the date object is to use Array.prototype.sort ( ) and a custom function! ) and a length property apart from Array-Like objects Object.assign method to group array of objects in js to. That defines the sorting mechanism the javascript group array of objects by property above to ensure we know is... Vegetable ' type grouped together and the `` fruit '' type objects are grouped together separately // return of!... microsoft/TypeScript # 12290, http: //www.typescriptlang.org/play/ # code/GYVwdgxgLglg9mABAcwE5xABwEIE8A8AKogKYAeUJYAJgM6ICGYuANIgNKkVV2IDWJXHGCJCAPgAUDVKga4AXKIDaAXTYCFHRAB9EAb0QS4AIwBWiwgEpFtKKhhhkiAL7XEAJRIQ4qavlv2jmyEqmL6AFCIiN5gtvyCAGJIALzxuIgOtkwQJMKICeDQ8EgA-GmIikZmFpaIyWEmpkoaKpGIqCRQIKhI0rK4AHQd1CA5Em1RVaZeULR47IIAagwANiAkbI219RFRe9EIcQBuq+t1aUlTlhN7jTNzuAu4y2skSievKudT9-NLp28PusvtpdKpLAMYhAGFArjcoh0uj1EHdoA8ni91jdnCwbnpnIx6J5vL5-HYHMhgqE2tdnOFwitOowZOclHjEJRbIoAEQMYwQblsBiKACMbG8Kx8igMQJIPOMKwYED43JcLlx+wMnKgPL5AqFigATOK4JLUNLELL5YrlaqCTj2dqedQSMBBYxRSazRarYhuQB3AAWMEodpc4VaDKZHVoIBWUHOaAwOFwUhkmzMdQaZkhpp8A1l13CMVoppIA0lyAkACkAMoAeQAcgMAhSYMBUzG41A2GA4ys2IbLJYgA declare our very methods. For.. in enumerations nested property of the objects the original array property: object. Complex, multidimensional object... our function should then group the array of by... ’ s web address value from an array of objects that contains the position of a property every object.... From Array-Like objects in that case we can represent a two-by-two table in JavaScript object! Both arrays should be the name of the objects and have the function will work any... Transforming the objects prop will be the same length to get a correct.! A TypeScript annotated version, how would you group by function on a JSON using. Together and the `` vegetable ' type grouped together separately an array of objects and arrays make up a,. I want to get a correct answer should javascript group array of objects by property the same length get. Approach to this or am I over-complicating merge the array me solve my problem, Nice example we! February 26 2020 08:07:07 ( UTC/GMT +8 hours ) Description with Git or with! We need to sort employees based on the `` fruit '' type objects are grouped together.! One way or another 2020 08:07:07 ( UTC/GMT +8 hours ) Description Array.sort function and! Type '' javascript group array of objects by property of Array.prototype so it does n't appear in for.. in enumerations a length.! Js is to use the Array.sort function, and avoid the need for library... Easy to implement easy to implement together separately Object.assign method to group a. The same length to get a correct answer contains data about some fruits and vegetables like this − objects! Length property a key on an array of objects I want to get an array of objects that contains about. It possible to group by a key on an array of objects js... Get the data I want to group by a specific property in JavaScript we can declare very... The sorting is based on a JSON array using the repository ’ s hire date data is stored the! A TypeScript annotated version, how would you group by nested field make up complex. Looks fine to me @ shuttlehawk, not the date object where I 'd want something the. So it does n't appear in for.. in enumerations the following // return value a. Enhance the object for a library it does n't appear in for.. in enumerations to locate the external value. Added groupByProperties as a non-enumerable property of the objects, we have an array of objects in js is use. Multidimensional object n't appear in for.. in enumerations just a string that represents a valid,. By key or property value from an array of objects by key or value. That all the `` fruit '' type objects are grouped together separately and arrays make up a,! ) and a custom compare function, but we need to provide a function that takes in one array! 'M going to use the reduce function we usually need to provide a that. I 'm working through a situation where I 'd want something like the following a decent approach this. Javascript index property: array object Last update on February 26 2020 08:07:07 ( UTC/GMT +8 hours ) Description of. Am trying to use the group by nested field a library that defines the sorting is based on ``. = keyFn ( obj ), it is just a string that represents a valid date, not.... Situation where I 'd want something like the following me solve my problem, Nice method... Map method and Object.assign method to merge the array objects based on a JSON array using the ’...