如何使用参数化名称创建数组? [英] how to create an Array with parametrized name?

查看:61
本文介绍了如何使用参数化名称创建数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


是否有一种方法可以在函数的帮助下创建一个数组

接受这个数组的名称作为参数然后创建全局

该名称的数组类型变量?

以便例如下面的代码在浏览器中也能正常工作

下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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆