xzegga
xzegga

Reputation: 3139

Convert javascript string formated like array to array object

I have receive a string with this format

"{'key': value}, {'key': value},{'key': value} ..."

I need to convert this string to javascript array to use like this:

var $arrayValue = [{'key': value}, {'key': value},{'key': value}];

how to conver this string into array?

Upvotes: 0

Views: 699

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107718

string = string = '{"key": "value"}, {"key": "value"}'
JSON.parse("[" + string + "]")

Upvotes: 3

Related Questions