maan81
maan81

Reputation: 3609

How to convert array of words to make a sentence?

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

Upvotes: 8

Views: 8517

Answers (3)

Snicksie
Snicksie

Reputation: 1997

Do you mean something like?

arr.join(" ");

Upvotes: 3

Steve Bergamini
Steve Bergamini

Reputation: 14600

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

a.join(" ");

Upvotes: 6

karim79
karim79

Reputation: 342635

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

Upvotes: 7

Related Questions