字符串转变量可以使用eval(aaa)

判断字符串对应的变量名是否存在: if(eval('typeof ' + "aaa") != "undefined") { ...}

举例:

var v1 = 100;
var v2 = 200 ;
	
console.log(eval("v1")); //100
console.log(eval("v2")); //200 
		
if(eval('typeof ' + "v3") != "undefined"){
	console.log(eval("v3")); //直接用会报错: Uncaught ReferenceError: v3 is not defined
}

参考: https://stackoverflow.com/questions/24001442/javascript-eval-referenceerror-is-not-defined