title: Javascript: Iterating over object and concatenate strings
body: <p>I have a Javascript object, which contains other objects. Each of the contained objects has got a <code>name</code> property. </p>
  
  <p>What I would like to do now is to concatenate these name properties to one String. However, I want these Strings separated by commas and an <code>'and'</code> before the last String. </p>
  
  <p>For better understanding, the object i want to iterate over would look like this:</p>
  
  <pre><code>var objects = {
      o1: {name: 'name1'}, 
      o2: {name: 'name2'},
      o3: {name: 'name3'}
  };
  </code></pre>
  
  <p>Now the String I would like to have in the end would be: <code>'Concatenation of name1, name2 and name3'</code></p>
  
  <p>What I've tried so far was using <code>angular.forEach</code>: </p>
  
  <pre><code>var myString = 'Concatenation of ';
  
  angular.forEach(objects, function(o) {
      myString += o.name + ', ';
  }
  </code></pre>
  
  <p>Not hard to notice, that my String would become <code>'Concatenation of name1, name2, name3, '</code>. </p>
  
  <p>So the real question would be how I can check at which position in my object I am and reacting appropiately by concatenating <code>'and'</code> instead of a comma or no comma at all. How can I do that?</p>