简体   繁体   English

如何在不使用eval的情况下将javascript中的嵌套数组字符串转换为不带引号的数组,字符串也可以是Z25F7E525B5C0641E1EB1FB3BDEBEB15B5Z的形式

[英]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.

相关问题 在没有eval()的情况下将字符串转换为javascript中的数组 - Converting a string to array in javascript without eval() javascript 中不带双引号的字符串数组 - String array without double quotes in javascript 如何在javascript中将字符串转换为数组而无需附加“和”, - how to convert string to array in javascript without additional " and , 如何在不使用eval的情况下将JS数组文字从HTML输入字符串转换为数组对象 - How to convert JS array literal from HTML input string to array object without using eval 如何在不使用eval()的情况下将完整功能字符串转换为javascript函数 - how to convert a full function string to a javascript function without using eval() JavaScript:将数组转换为无键或字符串的 object - JavaScript: Convert array to object without key or string Javascript:有没有办法在不使用eval()的情况下将字符串用作回调? - Javascript: Is there a way to use a string as a callback without eval()? 将对象转换为javascript中的字符串,而键中没有引号 - Convert Object to string in javascript without the quotes in key 如何在不丢失方括号的情况下将整数数组转换为javascript中的字符串 - How to convert an integer array into string in javascript without losing the square bracket 如何将字符串转换为数组,其中字符串为数组形式,字符串中的值在 latex - How to convert a string to array, where string is in array form, the values inside string are in latex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM