根据数组的维度轻松访问数组

发布于 2024-07-19 15:56:50 字数 501 浏览 8 评论 0原文

假设我有一个具有 n 维的数组。 现在,为了访问您通常使用的插槽:

 array [1][0]

如果在编译时未知维数,是否有一种简单的访问方式,例如:

 slot = "1,0"
 array [slot]   // accessing 1,0

这意味着我也可以轻松地来回导航

 slot += ",2"
 array [slot]   // accessing 1,0,2

任何这样的方式来访问任何插槽在 ActionScript 中,一行代码中的多维数组? 我不是在寻找替代代码,而是间接执行此操作(递归函数或循环)。

在 JavaScript 中你可以:

 slot = "1,0"
 eval("array[" + slot + "]")    // accessing 1,0

Lets say I have an array which has n dimensions. Now in order to access a slot you typically use:

 array [1][0]

What if the number of dimensions are not known at compile-time, is there an easy access like:

 slot = "1,0"
 array [slot]   // accessing 1,0

Which means I can also easily navigate back and forth

 slot += ",2"
 array [slot]   // accessing 1,0,2

Any such way to access any slot in a multidim array in one line of code, in ActionScript? I'm not looking for alternative code, that does it indirectly, (recursive functions or loops).

In JavaScript you could:

 slot = "1,0"
 eval("array[" + slot + "]")    // accessing 1,0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相权↑美人 2024-07-26 15:56:50

AS3 中没有这样的功能。 eval 也不是(主要是出于安全原因,IIRC)。 后者也是 AS3 与 ECMAScript 规范不同的少数几个领域之一。

There is no such facility in AS3. Neither is eval (taken out due to security reasons mostly, IIRC). The latter also being one of those few areas where AS3 differs from the ECMAScript specification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文