title: python dict.update() equivalent in javascript
body: <p>I want to update the dictionary in javascript- modify the existing values or add new values- same as python dictionary update.</p>
  
  <p>dict+ or dict.update() seem not be working. Is it possible to do so in javascript?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>data={"abc":{1:2,3:4}}
  
  if (key in d) {
              d[key].update(data[key]);
          }
          else {
              d[key]={};
              d[key]=data[key];
          }
  </code></pre>
  
  <p>EDIT: The updating dictionary is working fine as follow-</p>
  
  <pre><code>dg={"abc":{1:2,3:4},"sdc":{1:2,4:5}}
  function upd(data) {
      for (key in data) {
          if (key in dg) {
              for (key2 in data[key]) {
                  dg[key][key2]=data[key][key2];
              }
          }
          else {
              dg[key]={};
              for (key2 in data[key]) {
                  dg[key][key2]=data[key][key2];
              }
          }
  </code></pre>
  
  <p>but if i try separating the function as- </p>
  
  <pre><code>var old={};
  var new={};
  function update_dict(old,new) {
  console.log(new,old);
      for (key2 in new) {
                  old[key2]=new[key2];
              }
      return old;
  }
  function upd(data) {
  for (key in data) {
      if (key in dg) {
          dg[key]=update_dict(dg[key],data[key]);
      }
      else {
          dg[key]={};
          dg[key]=update_dict(dg[key],data[key]);
      }
  </code></pre>
  
  <p>It is throwing an error saying <strong>Uncaught SyntaxError: Unexpected token new</strong>. I have really tried a lot of permutations, please suggest. Thanks a lot!</p>