Reputation: 427
var checked1 = JSON.parse(Cookies.get('checkedValues'));
Now the checked1 contains: ,1
I used the following code to remove the trailing comma.
var checked = checked1.replace(/(^,)|(,$)/g, "");
But now i'm getting an error
Uncaught TypeError: checked1.replace is not a function
Upvotes: 0
Views: 49
Reputation: 427
var checked1 = JSON.parse(Cookies.get('checkedValues')).toString();
It Worked. The question was actually answered by Brian. But he removed his answer.
Upvotes: 0
Reputation: 2767
Try this
var checked1 = JSON.parse(Cookies.get('checkedValues').replace(/(^,)|(,$)/g, ""));
Upvotes: 2