I have 3 strings “a”,”b”,”c” in javascript array “testarray”.
var testarray=new Array("a","b","c");
and then I am printing the value of testarray using javascript alert box.
alert(testarray);
The result will be like a,b,c
All these strings are separated by “,” character. I want to replace this “,” with some other character or combination of two or more characters so that the alert box will show something like a%b%c or a%$b%$c
Use the
joinmethod:Here’s a working example. Note that by passing the empty string to
joinyou can get the concatenation of all elements of the array:Side note: it’s generally considered better practice to use an array literal instead of the
Arrayconstructor when creating an array: