I have the following Javascript code:-
const mainFunction = async (message) => {
const templateData = {};
templateData.name = message.firstName;
templateData.email = message.emailAddress;
templateData.account = message.accountType;
console.log("message::::", message);
const userId = message.userId;
const emailAddresses = [`${message.emailAddress}`];
console.log("emailAddresses->", emailAddresses);
}
Logs:-
2022-03-10T14:33:50.807+05:30
Copy
2022-03-10T09:03:50.806Z 8681ec6b-7f57-5148-bdd3-b6c8be7d2f15 INFO message::::
{
"userId": "b4c6cab0-a944-5f5e-81cd-b1dad4c0b54a",
"emailAddress": "tom.dick9000@gmail.com",
"notificationType": "NEW_USER_WELCOME_MESSAGE",
"firstName": "tom",
"lastName": "dick",
"accountType": "BASIC"
}
2022-03-10T09:03:50.806Z 8681ec6b-7f57-5148-bdd3-b6c8be7d2f15 INFO message:::: {"userId":"b4c6cab0-a944-5f5e-81cd-b1dad4c0b54a","emailAddress":"tom.dick9000@gmail.com","notificationType":"NEW_USER_WELCOME_MESSAGE","firstName":"tom","lastName":"dick","accountType":"BASIC"}
2022-03-10T14:33:50.807+05:30 2022-03-10T09:03:50.807Z 8681ec6b-7f57-5148-bdd3-b6c8be7d2f15 INFO emailAddresses-> [ 'undefined' ]
The problem is the constant emailAddress is coming as undefined but the value of the emailAddress attribute is present in the object message. I want to pass the dynamic value to this array of Strings but not working at all.
Please let me know why it is coming as undefined. Thanks