0

I have an array coming in string format. How do i convert it to an array.

my_data="['A','B','C']"  (Note the quotes around [])
convert this to ['A','B','C']

So far i tried json.parse and other string to array conversations without luck. Can anyone please help on this?

2
  • Remove extra characters and split by comma. Commented Apr 11, 2017 at 20:26
  • agree, but instead of string manipulation, there may be a way to convert this string into an array. Commented Apr 11, 2017 at 20:31

1 Answer 1

2

Replace the single quotes with double quotes using regex, then JSON.parse will work fine: JSON.parse(my_data.replace(/\'/g,"\""));

Single quotes are not valid characters for JSON data.

Sign up to request clarification or add additional context in comments.

1 Comment

It worked. you are right, single quotes seems to be a problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.