I have an object that looks like this:
var obj = {
a: "text",
b: "text 2",
c: "text 3",
...
}
and I have a bunch of strings that look like this:
var stringA = "http://{{a}}.something.com/",
stringB = "http://something.{{b}}.com/",
stringC = "http://something.com/{{c}}";
I want to replace {{(\w)}} with it’s equivalent by going through obj and checking if it has my matched value for every string, but I’m sure there is a better and faster way to do so.
Any ideas?
Douglas Crockford wrote a function called
supplantthat does almost exactly what you want. I’ve altered the function slightly to match your double curly braces –Demo – http://jsfiddle.net/saZGg/