1

So I have an array in a Javascript file that I want to display on my web page.

However, when I do it using

document.getElementById("fullVerb").innerHTML = thisVerb;

it is displayed without spaces. Like: first,second,third

How do I make it normally spaced (i.e. first, second, third)?

I can't just write the array in the HTML because it changes.

1
  • 3
    Use join: thisVerb.join(', '); Commented May 28, 2015 at 19:06

1 Answer 1

6

Use .join() for that purpose:

thisVerb = ['first', 'second', 'last'];
document.getElementById("fullVerb").innerHTML = thisVerb.join(', ');
// gets you: "first, second, last"

Demo

Try before buy

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.