Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add characters to a string in Javascript

People also ask

Can you add to a string in JavaScript?

In JavaScript, concat() is a string method that is used to concatenate strings together. The concat() method appends one or more string values to the calling string and then returns the concatenated result as a new string.

How do you add a letter to the end of a string in JS?

You can simply use + operator to add character to String in Javascript. As you can see, we have added char 't' to var str using + operator at the end.


let text = "";
for(let member in list) {
  text += list[member];
}

You can also keep adding strings to an existing string like so:

var myString = "Hello ";
myString += "World";
myString += "!";

the result would be -> Hello World!


simply used the + operator. Javascript concats strings with +


To use String.concat, you need to replace your existing text, since the function does not act by reference.

let text = "";
for (const member in list) {
  text = text.concat(list[member]);
}

Of course, the join() or += suggestions offered by others will work fine as well.


It sounds like you want to use join, e.g.:

var text = list.join();

Simple use text = text + string2