2

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.

1

1 Answer 1

12

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; }

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.