//Admin.js
var insertAdminFeed = function(s, id, timestamp){
var admin_att_new_key = '12345';
var admin_att_new_key2 = 'abc';
var admin_att_new_key3 = 'zyzyz';
var s = 'admin_att_new_key';
console.log(global[s]); //should print '12345'
};
exports.insertAdminFeed = insertAdminFeed;
I want to convert a string to a variable in node.js (I have many keys, and I don't want to write if/else statements for all of them) How can I do that?
var admin= {key:'12345',key2:'abc',key3:'zyzyzy'}and then use Object.keys(admin) to iterate through those keys when you need them.vars also scope tofunctions, andadmin_att_new_key{,2,3}seems rather like the start of anArray.