Python has this beautiful function to turn this:
bar1 = \'foobar\'
bar2 = \'jumped\'
bar3 = \'dog\'
foo = \'The lazy \' + bar3 + \' \' + bar2 \' over the \'
For those looking for a simple ES6 solution.
First of all I'm providing a function instead of extending native String prototype because it is generally discouraged.
// format function using replace() and recursion
const format = (str, arr) => arr.length > 1
? format(str.replace('{}', arr[0]), arr.slice(1))
: (arr[0] && str.replace('{}', arr[0])) || str
// Example usage
const str1 = 'The {} brown {} jumps over the {} dog'
const formattedString = formatFn(str1, ['quick','fox','lazy'])
console.log(formattedString)