Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 778
maan81 Avatar asked Sep 22 '11 10:09

maan81


People also ask

How to convert a sentence into string array in Java?

how to convert a sentence into string array in java Elisavet Apostolaki String str = "This is a simple sentence"; String[] strgs = str.split(" "); Add Own solution Log in, to leave a comment

How to split a sentence into an array of words in JavaScript?

Just use the split method to convert sentences into an array of words in JavaScript. You have to use a separator which uses to indicating where each split should occur. We will use a space separator, you can use a comma or another. JavaScript split a sentence into an array of words Example

How many sentences are in a string-array?

I'm having (in Java) String-Arrays like the following (more complicated, of course). Each String-Array represents one sentence (I cant change the representation):

How to split a string into an array of arrays?

You have to use a separator which uses to indicate where each split should occur. We will use a space separator, you can use a comma or another. HTML example code of split a string into an array of substrings, and returns the new array. Do comment if you have any doubts and suggestions on this JS array topic.


3 Answers

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

like image 52
karim79 Avatar answered Nov 05 '22 12:11

karim79


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

a.join(" ");
like image 31
SBerg413 Avatar answered Nov 05 '22 13:11

SBerg413


Do you mean something like?

arr.join(" ");
like image 35
Snicksie Avatar answered Nov 05 '22 13:11

Snicksie