Reputation: 1542
I want to remove all unnecessary spaces and commas from the start/end of the string.
eg; , 11,22,33 , should become 11,22,33
I tried this,
var str=",22,33,44,55,";
var splitted = str.split(",");
alert(splitted[0]);
But shows empty spaces
Upvotes: 1
Views: 854
Reputation: 122936
try:
var str=",22,33,44,55,";
str.replace(/^[\s,]+|[\s,]+$/g, '').split(",");
Upvotes: 4