I'm still new with Javascript and I'm not entirely sure how to go about this.
I want it to match the key field and replace it with its value.
const state = {
"NY": "New York"
}
You live in NY to You live in New York
The list is going to be quite long with all the states so I think I'll have to use objects. Any help would be appreciated! Thank you in advance!
EDIT>>>
Thank you so much to those that replied! I made a list of all the states for USA, Canada, and Mexico to their full name here: https://gist.github.com/PepperAddict/b8c6c80af4a17908fd98378b4375047e
using the code that was provided, I was able to change them all to their full name.
Thank you thank you thank you!
Object.keys(state).forEach(k => str = str.replace(k, state[k]))You live in ${arrayOfStates['NY']}