title: Add incrementing ID to obj in array
body: <p>Trying to add an ID to each object in an array. And if the id already exists the id will increment by 1, trying to get an auto increment function going. The problem is that with this function every object either gets the same ID when running the for loop inside the for each statement or I get cannot read <code>obj.id of undefined</code> if the loop runs outside.</p>
  
  <pre><code>function addId(arr, obj) {
    obj.id;
    arr.forEach(function(obj) {
      obj.id = 0;
      return obj.id;
    });
    for(var i = 0; i &lt;= arr.length; i++) {
      if(obj.id == obj.id) obj.id++;
    }
  };
  </code></pre>