ajithes1
ajithes1

Reputation: 427

Error while removing the trailing comma using javascript

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

Answers (2)

ajithes1
ajithes1

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

venkat7668
venkat7668

Reputation: 2767

Try this

var checked1 = JSON.parse(Cookies.get('checkedValues').replace(/(^,)|(,$)/g, ""));

Upvotes: 2

Related Questions