I have a string like this: var data = "[[1, 2, 3,], [3, 2, 1]]";
I am using the well known blossom function, which expects (as input) an array of this type: [[1, 2, 3,], [3, 2, 1]], [...], [...]]
As you can see, I am trying to provide this with my: data
variable, but this is currently a string, so I need to convert it to the right type. I know that I can convert a string to an array like this:
var input = "1, 2, 3";
var array = input.split(",");
Then the result of the above will be: ["1", "2", "3"]
But I need to be able to give input like this: var data = "[[1, 2, 3,], [3, 2, 1]]";
And expect this output: [[1, 2, 3,], [3, 2, 1]];
Also, notice that the values in the brackets are numbers and not string.
I also tried doing this:
var data = "[1, 2, 3,], [3, 2, 1]";
var res = data.split(",");
This gives the output: ["[1", " 2", " 3", "]", " [3", " 2", " 1]"]
Finally I also found this example: Convert string with commas to array where the solution made use of JSON.parse(...), but I did not make this work either.