Stefany
Stefany

Reputation: 145

How to remove a comma that separates the values from an array in JavaScript?

I have this code in JS:

var array = ['one', 'two'];

And each time I want to display the array, it is displayed with like this:

one,two

Now my question is, is there any way to remove that nasty comma?

Upvotes: 3

Views: 10419

Answers (2)

Joseph Sheedy
Joseph Sheedy

Reputation: 6736

You could use the replace method of the string object:

array.toString().replace(',',' ')

Upvotes: 1

Tim
Tim

Reputation: 5822

To display them next to each other, you can use join. array.join(' ');

Upvotes: 14

Related Questions