I have a an object with keys and values where the keys are variable names. e.g:
{name: 'Simon', gender: 'male', age: 43, country: 'UK'}
I also have a string/string literal where I need to replace words starting with '#' with their respective variables name. e.g
Hello my name is #name!
I'm a #age year old #gender living in the #country.
The final result would be:
Hello my name is Simon!
I'm a 43 year old male living in the UK.
Can I get some advice on how to do this in Javascript? So far I'm just iterating through the string and finding every occurrence of '#' and trying to replace it until I see the first delimeter/special char/white space etc but don't know how to put it into code.
for(let i = 0; i < string.length; i++){
if(string[i] == '#'){
//not sure how to complete it
}
}