我有一个 JSON 对象,其中有一个原始 SQL 查询,其中包含一个参数。我从 HTML DOM 元素获取参数的值。谁能告诉我如何更换它? 谢谢
EG:-
[1,2,"select * from animal where animal = @value"]
我想替换@value
最佳答案
如果那是一个字符串,您可以随时使用正则表达式。
let jsonValue = [1,2,"select * from animal where animal = @value"]
jsonValue[2] = jsonValue[2].replace(/@value/, 'tiger'); // output select * from animal where animal = tiger
关于javascript - 如何从 json 对象替换特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44669088/