151

How can I append a word to an already populated string variable with spaces?

0

4 Answers 4

347

Like this:

var str = 'blah blah blah';
str += ' blah';

str += ' ' + 'and some more blah';
Sign up to request clarification or add additional context in comments.

Comments

26
var str1 = 'abc';
var str2 = str1+' def'; // str2 is now 'abc def'

3 Comments

it's more of a onclick append to variable. can it be done with a single variable?
Sure thing. See my other answer below.
@Ronal - if there are any extra bits to your question, you should add them to the question rather than asking within the comments, including any information that might help you get a decent answer.
8
var str1 = "add";
str1 = str1 + " ";

Hope that helps,

Dan

Comments

5

Ronal, to answer your question in the comment in my answer above:

function wasClicked(str)
{
  return str+' def';
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.