I’m learning about javascript using dynamic variables. I’ve got the following code and associated error which i didnt understand. I’ve read a lot of responses to similar javascript dynamic code but they don’t use eval(). (I’m using eval() in nodejs)
let updatedArray = {
"firstNameArray": 'haha',
"lastNameArray": 'zaza',
"count": 0
};
let name = { "batch": "1" };
let firstNames_1 = [];
let lastNames_1 = [];
let count_1 = 0;
eval( 'firstNames_' + name.batch ) = updatedArray.firstNameArray;
eval( 'lastNames_' + name.batch ) = updatedArray.lastNameArray;
eval( 'count_' + name.batch ) = updatedArray.count;
I’ve tried running the above code but i’m stuck at this nodejs error.
ReferenceError: Invalid left-hand side in assignment
for eval( 'firstNames_' + name.batch ) = updatedArray.firstNameArray;
New contributor
Stanley T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.