Skip to content
Advertisement

Add characters to a string in Javascript

I need to add in a For Loop characters to an empty string. I know that you can use the function concat in Javascript to do concats with strings

var first_name = "peter"; 
var last_name = "jones"; 
var name=first_name.concat(last_name) 

But it doesn’t work with my example. Any idea of how to do it in another way?

My code :

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

Advertisement

Answer

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