KingK KingK - 5 months ago 9x
Javascript Question

Allowing commas to follow through when converting array to string [SOLVED]

I have an array of character with commas separating them. I need to split an array but retain my comma inbetween each character.

See below for an example array:

var myArray = [a,,,b,c,d,,,]

There's a comma in there between the characters "a" and "b". I need to retain the comma when converting the array to a string.

The output string needs to resemble this:


This is what i'm currently doing to retain the commas:

myArray.toString().replace(/,/g, "");


How about you use :

var myArray = [a,,,b,c,d,,,];
var str = myArray.join();

This will give a string of array elements, preserving the commas.