Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Merge Arrarys of Object of Any size

const arr1 = [
  { id: "abdc4051", date: "2017-01-24" }, 
  { id: "abdc4052", date: "2017-01-22" },
  { id: "abdc4053", date: "2017-01-22" }
];
const arr2 = [
  { nameId: "abdc4051", name: "ab" },
  { nameId: "abdc4052", name: "abc" }
];

const map = new Map();
arr1.forEach(item => map.set(item.id, item));
arr2.forEach(item => map.set(item.nameId, {...map.get(item.nameId), ...item}));
const mergedArr = Array.from(map.values());

console.log(JSON.stringify(mergedArr));
Comment

PREVIOUS NEXT
Code Example
Javascript :: Audio Stream from Server through Scoket 
Javascript :: arrow function no argument object 
Javascript :: logvalue returned from array 
Javascript :: enzyme to json 
Javascript :: search for country name from api with react 
Javascript :: how to replace import with require 
Javascript :: navigation with load page in angluar 
Javascript :: concatenate to require string in solidity ethereum 
Javascript :: event on trible click in js 
Javascript :: push code from vscode using CL 
Javascript :: test command in node js 
Javascript :: js remove null object 
Javascript :: javascript find the smallest and biggest number in array 
Javascript :: petru a retuna toate toate datele in java script 
Javascript :: onclick clear input field javascript 
Javascript :: how to set a custom error message to a form in angular 
Javascript :: detect paste in textarea 
Javascript :: how to put value in arrar 
Javascript :: javascript use numbers as objects 
Javascript :: javascript test https 
Javascript :: inherit mdn 
Javascript :: js to ts converter 
Javascript :: how to create a tag object in jQuery 
Javascript :: Ghost-Blog MySQL install was not found 
Javascript :: Function Returning This 
Javascript :: Backbone.model first parameter determines properties that each instance must have 
Javascript :: add a cumma in a number jquery 
Javascript :: Backbone Models In Collection Is Added Here 
Javascript :: stuck at "resvoling packages" 
Javascript :: fabric.js drawings 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =