javascript - 如何从 json 对象替换特定字符串

标签 javascript jquery html asp.net-mvc

我有一个 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/

相关文章:

javascript - 推送通知 Codelab 未捕获语法错误 : Unexpected identifier in curl request

javascript - Python 使用多个键对 JSON 对象进行分组

javascript - 如何在 angular2 *ngFor 中的每次迭代中调用组件中的方法?

jquery - Golang + JQuery + Smarty : How to iterate over object?

javascript - sharp (#) (e.g. #{$variable}) 在 SCSS 中是什么意思?

html - 如何在html/css中移动下拉菜单?

javascript - AngularJS 删除函数中的作用域变量

javascript - JavaScript 中的函数返回

html - 有没有办法让 iframe 全屏显示?

jquery - 带零的动画计数