javascript中具有自定义索引的多维数组

Ari*_*ant 0 javascript arrays multidimensional-array

如何在 javascript 中按以下格式制作多维数组:

Array[

{index}:{x-coords}
        {y-coords},

{index2}:{x-coords}
        {y-coords},
.... ];
Run Code Online (Sandbox Code Playgroud)

数据应如下所示:

Array[
{
indexabc:{10},{20}
},
{
indexxyz:{30},{40}
}
];
Run Code Online (Sandbox Code Playgroud)

另外,如何访问数组元素?我通过一个函数在其中存储值,因此它将被递归调用。

Wil*_*m B 5

听起来你想要普通的旧对象:

var o = {
  indexabc: { x: 10, y: 20},
  indexxyz: { x: 30, y: 40 }
};

console.log( o.indexabc.x, o.indexabc.y );
Run Code Online (Sandbox Code Playgroud)