In a specific scenario, I am working with a string that looks like this:
Edit: const message = results.doc.data().taskSettings.taskInProgressSettings.pushNotifications.onAssignmentNotifyEmployee.message;
The contents of the message vary and include variables such as taskId , customerName
. However, it can also contain other variables like
taskId , customerName , customerId, taskCreaterName , employeeName , employeeId
. I need to replace these variables with their corresponding values at runtime.
message:`Task ${taskId} assigned by ${taskCreaterName} for customer ${customerName}`
let taskId = T-100;
let taskCreaterName = 'mark';
let customerName = 'henry';
I wish to replace the variables (taskId , taskCreaterName , customername) with their actual values. The desired output should be:
newMessage = Task T-100 assigned by mark for customer henry
What would be the most effective approach to achieve this? Thank you