我希望能够通过使用字符串来引用数组,因为这样的:如何使用jQuery中的另一个变量通过名称引用变量?
var arrayName = "people";
var people = [
'image47.jpeg',
'image48.jpeg',
'image49.jpeg',
'image50.jpeg',
'image52.jpeg',
'image53.jpeg',
'image54.jpeg',
'image55.jpeg',
]
function myFunc (arrayName)
{
//arrayName is actually just a string that evaluates to "people", which then in turn would reference the var people, which is passed in.
}
如何做到这一点有什么想法?对不起,如果我错过了明显的东西。
'变种arrayName中的[] =人[]',这需要来_after_ var people []。 – Ohgodwhy 2012-03-20 02:09:01
看到这个http://stackoverflow.com/questions/952457/javascript-using-variable-as-array-name – 2012-03-20 02:13:30