我有一个这种格式的字符串:
"[0.00,0.10],[3.00,0.10],[6.00,0.10],[9.00,0.10],[12.00,662.00],[15.00,1186.00]"
Run Code Online (Sandbox Code Playgroud)
我想将它拆分成一个数组,以便最终的数组看起来像这样.基本上它们是[x,y]在高图表中使用的对.
[[0.00,0.10], [3.00,0.10], [6.00,0.10], [9.00,0.10], [12.00,662.00], [15.00,1186.00]]
Run Code Online (Sandbox Code Playgroud)
使用javascript这怎么可能?
我试过使用正则表达式,但似乎无法让它工作.
Nin*_*olz 12
你可以加上括号,并解析为JSON使用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);Run Code Online (Sandbox Code Playgroud)
.as-console-wrapper { max-height: 100% !important; top: 0; }Run Code Online (Sandbox Code Playgroud)