JB Sn John
JB Sn John

Reputation: 51

How to remove double quotes from outside of an Array?

I am taking data from the multiple select that gives me an array data. The data that I am getting is

{provinces: "["1","2"]"}

and when I stringify this data I got

{"provinces":"[\"1\",\"2\"]"}

But what I really want is

{"provinces":["1","2"]}

is there any way ?

Upvotes: 0

Views: 1151

Answers (1)

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41447

use the JSON.parse

var obj = {"provinces":"[\"1\",\"2\"]"} 

obj.provinces = JSON.parse(obj.provinces);
console.log(obj)

Upvotes: 3

Related Questions