title: How to merge two json object values by id with plain Javascript (ES6)
body: <p>I have two arrays of Javascript Objects and want to merge the properties of the two Javascript Objects with identical "ObjID" into one Javascript Object.</p>
  
  <p>For example:</p>
  
  <pre><code>// Array of Javascript Objects 1:
  let request1 = [{"ObjId":174864,"ObjMutationD":"2010-07-09T00:00:00.000Z","ObjMitarbeiterS":"epf","ObjAufId":142},
  {"ObjId":175999,"ObjMutationD":"2010-07-09T00:00:00.000Z","ObjMitarbeiterS":"epf","ObjAufId":149}]
  
  // Array of Javascript Objects 2:
  let request2 = [{"ObjId":174864,"MulPfadS":"M:\\Originalbilder\\FGS\\95nn","MulDateiS":"9576.305-034-1","MulExtentS":"jpg"},
  {"ObjId":177791,"MulPfadS":"M:\\Originalbilder\\FGS\\95nn","MulDateiS":"9576.305-035-1","MulExtentS":"jpg"}]
  </code></pre>
  
  <p>Merge into one Javascript object with the values of the same ObjId (see ObjID: 174864) and the rest (of the Objects) stays untouched:</p>
  
  <pre><code>let result = [{"ObjId":174864,"ObjMutationD":"2010-07-09T00:00:00.000Z","ObjMitarbeiterS":"epf","ObjAufId":142,
  "MulPfadS":"M:\\Originalbilder\\FGS\\95nn","MulDateiS":"9576.305-034-1","MulExtentS":"jpg"},
  {"ObjId":175999,"ObjMutationD":"2010-07-09T00:00:00.000Z","ObjMitarbeiterS":"epf","ObjAufId":149},
  {"ObjId":177791,"MulPfadS":"M:\\Originalbilder\\FGS\\95nn","MulDateiS":"9576.305-035-1","MulExtentS":"jpg"}]
  </code></pre>
  
  <p>What I tried so far:</p>
  
  <pre><code>let request1 = [{"ObjId":174864,"ObjMutationD":"2010-07-09T00:00:00.000Z","ObjMitarbeiterS":"epf","ObjAufId":142},
  {"ObjId":175999,"ObjMutationD":"2010-07-09T00:00:00.000Z","ObjMitarbeiterS":"epf","ObjAufId":149}]
  
  let request2 = [{"ObjId":174864,"MulPfadS":"M:\\Originalbilder\\FGS\\95nn","MulDateiS":"9576.305-034-1","MulExtentS":"jpg"},
  {"ObjId":177791,"MulPfadS":"M:\\Originalbilder\\FGS\\95nn","MulDateiS":"9576.305-035-1","MulExtentS":"jpg"}]
  
  function joinObjects() {
    var idMap = {};
    for(let i = 0; i &lt; arguments.length; i++) {
      for(let j = 0; j &lt; arguments[i].length; j++) {
         let currentID = arguments[i][j]['ObjId'];
         if(!idMap[currentID]) {
            idMap[currentID] = {};
          }
         // Iterate over properties of objects in arrays
        for(key in arguments[i][j]) {
            idMap[currentID][key] = arguments[i][j][key];
        }
      }
    }
  
    // push properties of idMap into an array
    let newArray = [];
    for(property in idMap) {
      newArray.push(idMap[property]);
    }
    return newArray;
  }
  
  let result = joinObjects(request1, request2);
  </code></pre>