【发布时间】:2016-11-24 13:46:46
【问题描述】:
我有以下对象数组,例如一些作者,我想通过它们进行映射并返回一个与某些格式连接的字符串。出于某种原因,我对这个相当简单的事情有疑问。
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"
我怎样才能让它映射并格式化为字符串?
例如"Steven is cool Nick is cool"
【问题讨论】:
-
您的浏览器及其版本?
-
只是
names.join(" ")?
标签: javascript arrays string ecmascript-6