I'm sending a string as parameter to a function, but i already have a global variable in that name, i want to get the value of that variable but its sending as undefined..
My example code
i have a array as reg,reg,reg,reg,reg,reg
and i have some global variables as tick1, tick2, tick3...
it will either have the values as 0,1 or 2
and in a function i called
calc_score(id) //id will return as either tick1,tick2,tick3
alert(eval("reg[id]")); // it should return the value of reg if id is 0
But its not working.
The id wont be a numeral it will be string .. So how can i do this?
以上就是Need to get the value of a variable which is sent as a string?的详细内容，更多请关注web前端其它相关文章！