reduce first string javascript code example
Example 1: 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 2: .reduce mdn
arr.reduce(callback( accumulator, currentValue[, index[, array]] )[, initialValue])