[英]How to convert a string of nested array to array without quotes in javascript without the use of eval, string can be also in a form of latex
How to convert a string of nested array to an array without quotes in javascript.如何在 javascript 中将嵌套数组的字符串转换为不带引号的数组。 I want to do without using
eval()
我不想使用
eval()
"[[[a,f],[b]],[[c]],[d],[e]]" into [[["a","f"],["b"]],[["c"]],["d"],["e"]]
d = eval("[[[a,f],[b]],[[c]],[d],[e]]".replace(/(\w+)/g, '"$1"'))
Gives the solution, but I don't want to use eval It can also be in latex "[[\\frac{a}{b}]]" for this JSON.parse won't work给出了解决方案,但我不想使用 eval 它也可以在 latex "[[\\frac{a}{b}]]" 对于这个 JSON.parse 不起作用
You could treat the new string as a JSON and parse it.您可以将新字符串视为 JSON 并对其进行解析。
let d = JSON.parse("[[[a,f],[b]],[[c]],[d],[e]]".replace(/(\w+)/g, '"$1"')); console.log(d);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.