Reputation: 8487
I have the following string:
var arr = "[{'one' : '1'}, {'two' : '2'}]";
How can I pass this string to an object?
I've tried the following but it doesn't seem to work:
arr.split(',');
Upvotes: 1
Views: 40
Reputation: 2306
you must first transform single quotes to double quotes then use JSON.parse
JSON.parse(arr.replace(/'/g,'"'))
Upvotes: 4