I am reading a value from a dropdown list depending on what option is selected. I am using jqPlot to graph the values.
jqPlot expects an array of values like [91, 6, 2, 57, 29, 40, 95]
but when I read the value in from the dropdown box it is coming in as a whole string "[91, 6, 2, 57, 29, 40, 95]"
I tried splitting it but I got ["91", "6", "2", "57", "29", "40", "95"] which wont display the graph correctly.
Is there anybody that has encountered something like this before and what can I do to make my values convert into a number array.
Thanks for any help
You can use
JSON.parse()to convert that string into a JavaScript array. The numbers in the string are not quoted so the array will also contain numbers. And you can delete all the code that parses the string as you won’t need it anymore.If you need to support legacy browsers, add json2.js to shim JSON support in browsers not supporting it natively.