How to convert array of words to make a sentence?

蓝咒 提交于 2020-06-23 06:20:11

问题


I feel uncomfortable asking, but how do I convert an array of words to make a sentence ?

I keep finding the other way round.

Something like:

var a = ['hello', 'world'];

and obtain :

hello world

回答1:


This doesn't need jquery. Javascript has a very simple way of doing this with the join function:

a.join(" ");



回答2:


Just join the elements of the array into a string using a space as a separator:

var sentence = a.join(" ");

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/join




回答3:


Do you mean something like?

arr.join(" ");


来源:https://stackoverflow.com/questions/7513129/how-to-convert-array-of-words-to-make-a-sentence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!