如何使用参数化名称创建数组? [英] how to create an Array with parametrized name?
问题描述
大家好,
是否有一种方法可以在函数的帮助下创建一个数组
接受这个数组的名称作为参数然后创建全局
该名称的数组类型变量?
以便例如下面的代码在浏览器中也能正常工作
下Windows脚本主持人:
str =" tableA";
fDoArray(str);
fDoArray( " tableB");
tableA [10] = 10;
tableB [11] = 11;
我将不胜感激任何建议和帮助,
问候,
mirek
您好,
< script>
函数fDoArray(arrayName)
{
window [ arrayName] = new Array();
}
str =" tableA";
fDoArray( str);
fDoArray(" tableB");
tableA [10] = 10;
tableB [11] = 11;
alert(tableB);
alert(tableA);
< / script>
-
Elias
http://lgwm.org/
" nobody" <无**** @ non.existe.nt>在留言中写道
news:b2 ********************* @ news.chello.at ...大家好,
有没有办法在一个函数的帮助下创建一个数组,该函数将接受这个数组的名称作为参数然后创建全局
数组该名称的类型变量?
因此,例如以下代码在Windows Scripting Host下的浏览器中也可以正常工作:
str =" tableA";
fDoArray(str);
fDoArray(" tableB");
tableA [10] = 10;
tableB [11] = 11;
我将不胜感激任何建议和帮助,
问候,
mirek
" nobody" <无**** @ non.existe.nt>写道:
有没有办法在一个函数的帮助下创建一个数组,该函数将接受这个数组的名称作为参数,然后创建全局
该名称的数组类型变量?
因此,例如以下代码在Windows Scripting Host下的浏览器中也可以正常工作:
str =" tableA";
fDoArray(str);
fDoArray(" tableB");
tableA [10] = 10;
tableB [11] = 11;
函数fDoArray(str){
window [str] = new Array();
返回窗口[str];
}
你好,
感谢Vjekoslav和Elias。你知道任何解决方案吗?在Windows Scripting Host下你也可以工作吗?
欢呼,
mirek
hello everybody,
is there a way of creating an array with help of a function that would
accept the name of this array as a parameter and then create global
Array type variable of that name?
so that for example the following code would work as well in browsers as
under Windows Scripting Host:
str = "tableA";
fDoArray(str);
fDoArray("tableB");
tableA[10] = 10;
tableB[11] = 11;
I would appreciate any suggestions and help,
regards,
mirek
Hello,
<script>
function fDoArray(arrayName)
{
window[arrayName] = new Array();
}
str = "tableA";
fDoArray(str);
fDoArray("tableB");
tableA[10] = 10;
tableB[11] = 11;
alert(tableB);
alert(tableA);
</script>
--
Elias
http://lgwm.org/
"nobody" <no****@non.existe.nt> wrote in message
news:b2*********************@news.chello.at...hello everybody,
is there a way of creating an array with help of a function that would
accept the name of this array as a parameter and then create global
Array type variable of that name?
so that for example the following code would work as well in browsers as
under Windows Scripting Host:
str = "tableA";
fDoArray(str);
fDoArray("tableB");
tableA[10] = 10;
tableB[11] = 11;
I would appreciate any suggestions and help,
regards,
mirek
"nobody" <no****@non.existe.nt> wrote:
is there a way of creating an array with help of a function that would
accept the name of this array as a parameter and then create global
Array type variable of that name?
so that for example the following code would work as well in browsers as
under Windows Scripting Host:
str = "tableA";
fDoArray(str);
fDoArray("tableB");
tableA[10] = 10;
tableB[11] = 11;
function fDoArray(str){
window[str]=new Array();
return window[str];
}
hello,
thanks Vjekoslav and Elias. do you know any solution, that would also
work under Windows Scripting Host?
cheers,
mirek
这篇关于如何使用参数化名称创建数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!