Append to string variable

JavascriptStringVariablesAppend

Javascript Problem Overview


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

Javascript Solutions


Solution 1 - Javascript

Like this:

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

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

Solution 2 - Javascript

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

Solution 3 - Javascript

var str1 = "add";
str1 = str1 + " ";

Hope that helps,

Dan

Solution 4 - Javascript

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRonalView Question on Stackoverflow
Solution 1 - Javascriptkarim79View Answer on Stackoverflow
Solution 2 - JavascriptJames SkidmoreView Answer on Stackoverflow
Solution 3 - JavascriptDaniel ElliottView Answer on Stackoverflow
Solution 4 - JavascriptJames SkidmoreView Answer on Stackoverflow