I have a string, where I want to replace global myObj.value with myObj.name. I tried to construct a new RegExp object, but how to pass the square brackets ?
let param = {
name: '[year]',
value: '2019'
}
let str = 'Enter the number of days during [year] (they should not be more than your total days spent
during [year])'
I tried:
str.replace(new RegExp('param.name', 'g'), param.value);
and
str.replace(new RegExp(`\\[param.name\\]`, 'g'), param.value)