英文:
How can I use a constant to call on something?
问题
When I try to add a variable into a calling on a required value.
我尝试将一个变量添加到对所需值的调用中。
I am trying to input the constant cookieinfo into calling on a cookie value.
我正在尝试将常量cookieinfo输入到对cookie值的调用中。
const cookieinfo = "bot" + result.bot
const config = require('/Users/Owner/Downloads/RankBloxCode/config');
const bloxy = require('bloxy');
const robloxClient = new bloxy.Client({
credentials: {
cookie: config.cookieinfo
}
});
//Input
result.bot = abc
//Output
output = config.botABC
英文:
When I try to add a variable into a calling on a required value.
I am trying to input the constant cookieinfo in to calling on a cookie value.
const cookieinfo = "bot" + result.bot
const config = require('/Users/Owner/Downloads/RankBloxCode/config');
const bloxy = require('bloxy');
const robloxClient = new bloxy.Client({
credentials: {
cookie: config.cookieinfo
}
});
//Input
result.bot = abc
//Output
output = config.botABC
答案1
得分: 0
除非我误解了你的问题,你必须使用方括号表示法来处理动态键(点表示法仅适用于静态键)。
所以 config.cookieinfo
必须是 config[cookieinfo]
。
英文:
unless I'm misunderstanding your problem, you must use bracket notation for dynamic keys (dot notation only works with static keys).
so config.cookieinfo
has to be config[cookieinfo]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论