I am trying to interpolate variables in strings in JavaScript. I want to interpolate the words_to_be_removed variable with the defaultMessageTest string. I have tried the below 3 methods but none of them working.
String text ${expression}
- "String text ${expression}"
- "String text " + expression " String text"
function remove_alert_word(alert_word) {
const words_to_be_removed = [alert_word];
const defaultMessageTest = "Alert word ${words_to_be_removed} removed successfully!";
channel.del({
url: "/json/users/me/alert_words",
data: {alert_words: JSON.stringify(words_to_be_removed)},
success() {
update_alert_word_status(
$t({defaultMessage: defaultMessageTest}),
false,
);
},
error() {
update_alert_word_status($t({defaultMessage: "Error removing alert word!"}), true);
},
});
}