Remove leading comma from a string

To remove the first character you would use:

var myOriginalString = ",'first string','more','even more'"; 
var myString = myOriginalString.substring(1);

I'm not sure this will be the result you're looking for though because you will still need to split it to create an array with it. Maybe something like:

var myString = myOriginalString.substring(1);
var myArray = myString.split(',');

Keep in mind, the ' character will be a part of each string in the split here.


var s = ",'first string','more','even more'";

var array = s.split(',').slice(1);

That's assuming the string you begin with is in fact a String, like you said, and not an Array of strings.


One-liner

str = str.replace(/^,/, '');

I'll be back.


In this specific case (there is always a single character at the start you want to remove) you'll want:

str.substring(1)

However, if you want to be able to detect if the comma is there and remove it if it is, then something like:

if (str[0] == ',') { 
  str = str.substring(1);
}