Question

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

Was it helpful?

Solution

Like this:

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

str += ' ' + 'and some more blah';

OTHER TIPS

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

Hope that helps,

Dan

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

function wasClicked(str)
{
  return str+' def';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top