I have an javascript array of string that looks like:
A = ['a', 'b', 'c'];
I want to convert it to (all string):
strA = '"a","b","c"'
How do I achieve this?
You can use join with "," as glue.
var strA = '"' + A.join('","') + '"';
join will only add the glue between the array elements. So, you've to add the quotes to start and end of it.
var strA = '"' + A.join('","') + '"';Try this
A = ['a', 'b', 'c'];
A.toString();
alert(A);
a, b and c.You could try just concatenating the values in a simple for loop something like this:
var array = ["1", "a", 'b'];
var str = '';
for (var i = 0; i<array.length; i++){
str += '"' + array[i] + '",';
}
str = str.substring(0, str.length - 1);
or if you're feeling crazy you could do :
str = JSON.stringify(array)
str = str.substring(1, str.length -1);
'a, b , c'->strA = A.join(', ')- Array.join()\"a\",\"b\",\"c\", I am just looking for a simple solution'"' + A.join('", "') + '"';