views:

3930

answers:

4

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

A: 
var str1 = 'abc';
var str2 = str1+' def'; // str2 is now 'abc def'
James Skidmore
it's more of a onclick append to variable. can it be done with a single variable?
Ronal
Sure thing. See my other answer below.
James Skidmore
@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.
karim79
no problem. much thanks
Ronal
+5  A: 

Like this:

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

str += ' ' + 'and some more blah';
karim79
A: 
var str1 = "add";
str1 = str1 + " ";

Hope that helps,

Dan

Daniel Elliott
A: 

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

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