title: replace value if key is same in json object
body: <p>I have following array which consist of json objects:</p>
  
  <pre><code>items = [{"Id":"car","color":"blue"},{"Id":"truck","color":"red"}]
  </code></pre>
  
  <p>I have new json object. If the "Id" of this object(newItem) matches the "Id" in items, i would like to replace the "color" value.</p>
  
  <pre><code>newItem = {"Id":"car","color":"yellow"}
  </code></pre>
  
  <p>So, i would like output like this: </p>
  
  <pre><code>items = [{"Id":"car","color":"yellow"},{"Id":"truck","color":"red"}] 
  </code></pre>
  
  <p>Here's what i have so far:</p>
  
  <pre><code>for (var i=0; i&lt;items.length; i++) {
      var x = items[i];
  
      if(x.Id == newItem.Id){    //first check if id matches  
          if (JSON.stringify(items[i]) == JSON.stringify(newItem))  { 
              alert('objects are same');                        
              return ;           
          } 
          else {
              var newColor = JSON.stringify(x).replace(x.color, newItem.color);
              alert(JSON.parse(newColor));
  
          }
      }            
  }
  </code></pre>