reduce array of objects to array of strings code example

Example 1: js reduce a array of straing

var authors = [{name: 'some author'},{name: 'another author'},{name: 'last author'}]
var authorString = authors.map(function(author){
    return author.name;
}).join(",");
console.log(authorString);

Example 2: reduce an array of objects to string

var authors = [{
  name: "a"
}, {
  name: "b"
}, {
  name: "c"
}];
var result = authors.reduce(function(author, val, index) {
  var comma = author.length ? ", " : "";
  return author + comma + val.name;
}, '');
console.log(result);

Example 3: js reduce a array of straing

var authors = ['some author', 'another author', 'last author'];
var authorString = authors.join(",");
console.log(authorString);