Reputation:
I have a JSON object in which I am having a RAW SQL query with a parameter inside it. I am getting the value of the parameter from my HTML DOM element. HOW to replace it can any one tell me? thanks
EG:-
[1,2,"select * from animal where animal = @value"]
i want to replace @value
Upvotes: 0
Views: 736
Reputation: 3348
If thats a string you can always use regex.
let jsonValue = [1,2,"select * from animal where animal = @value"]
jsonValue[2] = jsonValue[2].replace(/@value/, 'tiger'); // output select * from animal where animal = tiger
Upvotes: 3
Reputation: 670
If you include the Lodash library in you project you can use this method, otherwise you need to use the traditional javascript replace method.
_.replace(array[2], '@value', 'my new value');
Upvotes: 1