从JavaScript中有效地获取JavaScript中的值

时间:2017-08-12 22:53:11

标签: javascript

如何从JavaScript中的字符串中获取变量/属性?

字符串for (unsigned int i = 0; i < count; i++) { boost::thread z(CommandLineRun, nIndex[i].line); // refer to the original string. z.detach(); // making this explicit makes your intent clear } void CommandLineRun(std::string Command) // getting a copy of the string { int systemRet = system(Command.c_str()); if(systemRet == -1){ // The system method failed } } 返回obj.val的值。将obj.val添加到字符串的开头和结尾足够了吗? 谢谢! :)

与你们有些人建议的帖子不同,我想要的值没有字符串键。

1 个答案:

答案 0 :(得分:0)

您可以使用variablestring this[yourString]获得scope[yourString]的价值。

var someVar = "Hello world!";
this["someVar"] //this print value of variable name "someVar"

var obj = {}; obj.var = "some object!";
this["obj"]["var"] //this will get value of object property with "var"