title: How to update an array of object in javascript
body: <p>say I have a variable </p>
  
  <pre><code> data=[] 
  
   //this variable is an array of object like 
   data = [
       {name:'a',value:'aa'},
       {name:'b',value:'bb'}
   ]
  
   // the data structrue can not be changed and the initial value is empty
  </code></pre>
  
  <p>now I want to update the data</p>
  
  <pre><code> function updateData(){
       if(!data.length){
           data.push(arguments)
       }
       else{
           //this parts really confuse me
       }
  
   }
  </code></pre>
  
  <p>this function must accept any number of arguments,and the order of the objects in data dose not matters
  <strong>update rule</strong>:</p>
  
  <ol>
  <li>update the objects value to the arguments value if they have the same name.</li>
  <li>add the arguments to the data if none of the object in data have the same name.</li>
  </ol>
  
  <p>how to write this function?</p>
  
  <pre><code> updateData([
       {name:'a',value:'aa'},
       {name:'b',value:'bb'}
   ])
   // expect data = [
             {name:'a',value:'aa'},
             {name:'b',value:'bb'}
             ]
  
   updateData([
       {name:'a',value:'aa'},
       {name:'b',value:'DD'},
       {name:'c',value:'cc'}
  ] )
   // expect data = [
             {name:'a',value:'aa'},
             {name:'b',value:'DD'},
             {name:'c',value:'cc'}
             ]
  </code></pre>