title: VueJS get unique values from array of objects based on key in watch
body: <p>I have a watch to check the selected tags:</p>
  
  <pre><code>watch: {
    search (val) {
      for (let i = 0; i &lt; val.length; i++) {
        this.form_data.products_credit.push({
          product_id: val[i].id,
          quantity: null,
          package_size: null,
          purchase_price: null,
          warehouse_id: null
        });
      }
    }
  }
  </code></pre>
  
  <p>This works fine but the problem when the user select for example <strong>tag1</strong> then 
  <code>this.form_data.products_credit</code> value is equal to:</p>
  
  <pre><code>[
    {
      product_id: 1,
      quantity: null,
      package_size: null,
      purchase_price: null,
      warehouse_id: null
    }
  ]
  </code></pre>
  
  <p>After that if the user selected <strong>tag2</strong> then <code>this.form_data.products_credit</code> result will be:</p>
  
  <pre><code>[
        {
          product_id: 1,
          quantity: null,
          package_size: null,
          purchase_price: null,
          warehouse_id: null
        },
        {
          product_id: 2,
          quantity: null,
          package_size: null,
          purchase_price: null,
          warehouse_id: null
        },
        {
          product_id: 2,
          quantity: null,
          package_size: null,
          purchase_price: null,
          warehouse_id: null
        }
      ]
  </code></pre>
  
  <blockquote>
    <p>What I am expecting:</p>
  </blockquote>
  
  <p>I was not expecting the duplicated that happened after selecting another tag but that is normal since I am looping throw them.</p>
  
  <blockquote>
    <p>What I have done:</p>
  </blockquote>
  
  <p>I have tried to empty my <code>products_credit</code> before the loop like this:</p>
  
  <p><code>this.form_data.products_credit = []</code></p>
  
  <p>before the loop.</p>
  
  <p>It worked fine but I don't want it that way because it will has side-effects on my next step.</p>
  
  <p>A working example of the problem: <a href="https://jsfiddle.net/bLofrxye/" rel="nofollow noreferrer">here</a></p>