Reputation: 199
I have a string in this format:
"[0.00,0.10],[3.00,0.10],[6.00,0.10],[9.00,0.10],[12.00,662.00],[15.00,1186.00]"
I want to split it into an array so that the final array would look like this. Basically they are [x,y]
pairs to use in a highcharts chart.
[[0.00,0.10], [3.00,0.10], [6.00,0.10], [9.00,0.10], [12.00,662.00], [15.00,1186.00]]
Using javascript how is this possible?
I have tried using regular expression, but cannot seem to get it to work.
Upvotes: 2
Views: 120
Reputation: 386570
You could add brackets and parse as JSON with JSON.parse
.
var string = "[0.00,0.10],[3.00,0.10],[6.00,0.10],[9.00,0.10],[12.00,662.00],[15.00,1186.00]",
array = JSON.parse('[' + string + ']');
console.log(array);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Upvotes: 12