title: How to remove duplicates in array by choosing which one to keep?
body: <h1>The problem</h1>
  
  <p>I have a Javascript array that can contains duplicates (only 2) having same value for the key <code>color</code>.</p>
  
  <pre><code>  var array = [
      {
        "id": "1",
        "color": "red",
        "animal": null
      },
      {
        "id": "2",
        "color": "red",
        "animal": "cat"
      },
      {
        "id": "3",
        "color": "green",
        "animal": "dog"
      }
    ];
  </code></pre>
  
  <p>I'd like to remove duplicates on key <code>color</code> and only keep the unique object having the key <code>animal</code> not <code>null</code>.</p>
  
  <pre><code>  var uniqueArray = [
      {
        "id": "2",
        "color": "red",
        "animal": "cat"
      },
      {
        "id": "3",
        "color": "green",
        "animal": "dog"
      }
    ];
  </code></pre>
  
  <h1>What I tried</h1>
  
  <pre><code>  var obj = {};
  
    for (var i = 0; i &lt; array.length; i++) {
      obj[array[i]['name']] = array[i];
    }
  
    var uniqueArray = new Array();
    for (var key in obj) {
      uniqueArray.push(obj[key]);
    }
  </code></pre>
  
  <p>Here's the result :</p>
  
  <pre><code>var uniqueArray = [
      {
        "id": "1",
        "color": "red",
        "animal": "null"
      },
      {
        "id": "3",
        "color": "green",
        "animal": "dog"
      }
    ];
  </code></pre>
  
  <p>I don't know how to choose which object I want to keep.</p>
  
  <p><em>Note : I can't use ES6</em></p>