TIL Replace Only Fixes the First Encounter
POSTED ON:
TAGS: javascript mdn
For Replace, it will find and replace the first occurrence.
Instead, you want to use ReplaceAll
const petName = 'Leo'
const placeholder = '{NAME}'
const reminderTemplate = '{NAME} is due for another visit. Please call us so we can set up a new appointment. We look forward to seeing you and {NAME} soon.'
const reminder = reminderTemplate.replaceAll(placeholder, petName)
Related TILs
Tagged: javascript