I have a string "my name is {{name}} and i m from {{location}}" and an object {"name":"John", "location":"Hyderabad"}. I have to replace the keys in the string with the values of the object.
I tried with this code
let finalString = "my name is {{name}} and i m from {{location}}".replace(/\{{(.*)}}/g, function(a,b){
return object[b]
});
but its taking the first and last pair of braces in the whole string. Can any one suggest the right way of doing this.
The expected answer is My name is john and i am from hyderabad