有没有一种优雅的方法可以在 foreach() 之后链接 join()?

Is there an elegant way to chain join() after a foreach()?

我想写这样的东西:

DOMElement
 .innerHTML
 .toLowerCase()
 .split(' ')
 .forEach(function(word) {
   return word.charAt(0).toUpperCase() + word.slice(1);
 })
 .join(' ')

由于 join 需要接收一个 array,有没有一种优雅的方式来提供它?

您可以替换 Array#forEach with Array#map.

The map() method creates a new array with the results of calling a provided function on every element in this array.

.map(function(word) {
    return word.charAt(0).toUpperCase() + word.slice(1);
})