title: How to use javascript reduce function for objects in an array to get string values
body: <p>I have an array of objects from which  I would like to get names. I am trying to use reduce for that but the problem is that reduce returns the first values as undefined and only returns the last value in the array. I wonder why that is? How does reduce works with strings inside objects?</p>
  
  <p>my code:</p>
  
  <pre><code>    var data = [ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ]
  
      var result = function(){
  
      var names = data.reduce(function(a, b){
      return  a.name + ',' + b.name
      })
      return names
  
      };
  
      var res = result();
      console.log(res)
  
  **`output // undefined,Maggie`**
  </code></pre>
  
  <p><a href="https://jsfiddle.net/yo3rjuvm/1/" rel="nofollow noreferrer">fiddle</a></p>