0
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

4
  • try first remove the comma the JSON.parse it. Commented Dec 7, 2017 at 6:01
  • 1
    "Now the checked1 contains: ,1" <- I highly doubt that unless you're referring to a property value within the checked1 object Commented Dec 7, 2017 at 6:01
  • You cannot use the replace function on an object, only a string. JSON.parse() returns an object. Commented Dec 7, 2017 at 6:03
  • thank you Brian.. it workss.... :) Commented Dec 7, 2017 at 6:03

2 Answers 2

2

Try this

var checked1 = JSON.parse(Cookies.get('checkedValues').replace(/(^,)|(,$)/g, ""));
Sign up to request clarification or add additional context in comments.

Comments

0
var checked1 = JSON.parse(Cookies.get('checkedValues')).toString();

It Worked. The question was actually answered by Brian. But he removed his answer.

3 Comments

var checked= JSON.stringify(checkedValue); Cookies.set('checkedValues', checked); //cookie was set using JSON.stringify.
If it is already stringify , you can replace the ,1 without parseing the cookie..
is it? anyway now the problem solved. thank you for the suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.