如何检查变量名(标识符)中是否存在字符串值 例如:
let stringVar = "hello";
let helloJohny = 45;
if (stringVar in helloJohny(name)) {
return true;
}
其中“helloJohny(name)”仅表示标识符,而不表示为此标识符存储的值。
或者根据字符串值设置标识符? 例如:
let stringVar1 = "pretty";
let stringVar2 = "horse";
let (stringVar1 + stringVar2) = 45;
其中: (stringVar1 + stringVar2) 只是表示由两个字符串值构建的标识符,在本例中为 Prettyhorse,因此系统中的结果必须理解为
let prettyhorse = 45;
???
最佳答案
JavaScript 中的对象允许使用变量和表达式访问属性。
let stringVar1 = "pretty";
let stringVar2 = "horse";
let content = {};
content[stringVar1 + stringVar2] = 45;
console.log(content.prettyhorse);
关于javascript - 检查 JS 或 TS 中的标识符中是否存在字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54148450/