映射数组中的属性并在JavaScript es6中连接一个字符串

svn*_*vnm 5 javascript arrays string ecmascript-6

我有以下数组对象,例如一些作者,我想通过它们进行映射并返回一个已与某些格式连接的字符串.我出于某种原因遇到了这个相当容易的问题.

const authors = [ { id: 1, name: 'Steven'}, {id: 2, name: 'Nick'}]
let names = authors.map( (a, i) => {
  return `${a.name} is cool`
})
console.log(names)
// ["Steven is cool","Nick is cool"]
// but I really want the string "Steven is cool Nick is cool"
Run Code Online (Sandbox Code Playgroud)

我怎样才能将其映射并将其格式化为字符串?

例如 "Steven is cool Nick is cool"

Abd*_*UMI 17

用途Array#Join:

authors.map((a) => `${a.name} is cool`).join(' ');
Run Code Online (Sandbox Code Playgroud)

DEMO


注意:join与ES6无关,它已经过时了.