不确定此问题的最佳标题,因此欢迎提出任何修订建议...

说我有1个如下所示的javascript数组:

group[g1] = [v1,v2,v3]
group[g2] = [a1,a2,a3]
group[g3] = [b1,b2,b3]
and so on... ad infinitum


我想重新排列以获得

newgroup[z] = [v1,a1,b1]
newgroup[y] = [v1,a1,b2]
newgroup[x] = [v1,a1,b3]
newgroup[w] = [v1,a2,b1]
newgroup[v] = [v1,a2,b2]
newgroup[u] = [v1,a2,b3]
newgroup[t] = [v1,a3,b1]
newgroup[s] = [v1,a3,b2]
newgroup[r] = [v1,a3,b3]
newgroup[q] = [v2,a1,b1]
newgroup[p] = [v2,a1,b2]
newgroup[o] = [v2,a1,b3]
newgroup[n] = [v2,a2,b1]
newgroup[m] = [v2,a2,b2]
newgroup[h] = [v2,a2,b3]
newgroup[g] = [v2,a3,b1]
newgroup[f] = [v2,a3,b2]
newgroup[d] = [v2,a3,b3]
newgroup[q] = [v3,a1,b1]
newgroup[p] = [v3,a1,b2]
newgroup[o] = [v3,a1,b3]
newgroup[n] = [v3,a2,b1]
newgroup[m] = [v3,a2,b2]
newgroup[h] = [v3,a2,b3]
newgroup[g] = [v3,a3,b1]
newgroup[f] = [v3,a3,b2]
newgroup[d] = [v3,a3,b3]


即列出所有将这些项目分组的不同方式的排列列表
理想情况下,这是动态的,因此无论每个组数组中有多少组元素,它也都可以工作。
然后,我可以加入新闻组并将它们链接在一起,从而为jquery制作一个大型选择器。

请帮助...现在超越了我!

最佳答案

我意识到我正在寻找原始阵列的笛卡尔积。并在这里找到结果。Lazy Cartesian product of arrays (arbitrary nested loops)…天哪,我喜欢这个网站

09-13 14:32