将所有双引号替换为JavaScript中的括号?

时间:2019-01-03 19:06:09

标签: javascript replace

这是一个示例字符串变量:

var abc='[{"choices":"[1,2,598,214,14]","question":"There is a tom","correctAnswer":"2"},{"choices":"[1,2,598,214,14]","question":"There is a tom1","correctAnswer":"3"},{"choices":"[1,2,598,214,14]","question":"There is a tom2","correctAnswer":"4"},{"choices":"[1,2,598,214,14]","question":"There is a tom3","correctAnswer":"1"}]'

我想将"choices":"[1,2,598,214,14]"替换为此"choices":[1,2,598,214,14]并替换其他所有字符串(全局在字符串中)。 我尝试了这些:

abc.replace('"[', '[');
abc.replace(/"[/g, '['); //This also not worked though

但这仅替换第一个实例,然后停止。 我该怎么做呢? 谢谢!

0 个答案:

没有答案