如何动态导航javascript多维数组?

如何动态导航javascript多维数组?,javascript,arrays,json,Javascript,Arrays,Json,我有两个数组,如下所示: vars arrayVars = ["s", "p", "o"] arrayBindings = [ { "s": { "type": "uri" , "value": "http://ss.ldm.io/" } , "p": { "type": "uri" , "value": "http://xmlns.com/foaf/0.1/name" } , "o": { "type": "literal" , "va

我有两个数组,如下所示:

vars arrayVars = ["s", "p", "o"]

arrayBindings = [     {
        "s": { "type": "uri" , "value": "http://ss.ldm.io/" } ,
        "p": { "type": "uri" , "value": "http://xmlns.com/foaf/0.1/name" } ,
        "o": { "type": "literal" , "value": "ss" }
      } ,
      {
        "s": { "type": "uri" , "value": "http://ss.ldm.io/" } ,
        "p": { "type": "uri" , "value": "http://xmlns.com/foaf/0.1/img" } ,
        "o": { "type": "uri" , "value": "http://fbcdn-sphotos-d-a.akamaihd.net/o.jpg" }
      },
      ...
      ]
我希望能够根据第一个参数动态导航
阵列绑定
,基本上:


数组绑定[0]。s.value
获取我的
“http://ss.ldm.io/“
但以类似于
arrayBindings[0].arrayVars[0].value的方式进行操作,
这是[]符号派上用场的地方:

arrayBindings[0][arrayVars[0]].value
var arrayVars=[“s”、“p”、“o”]
变量数组绑定=[{
“s”:{“类型”:“uri”,“值”:”http://ss.ldm.io/" } ,
p:{“类型”:“uri”,“值”:http://xmlns.com/foaf/0.1/name" } ,
“o”:{“type”:“literal”,“value”:“ss”}
} ,
{
“s”:{“类型”:“uri”,“值”:”http://ss.ldm.io/" } ,
p:{“类型”:“uri”,“值”:http://xmlns.com/foaf/0.1/img" } ,
o:{“类型”:“uri”,“值”:http://fbcdn-sphotos-d-a.akamaihd.net/o.jpg" }
},
]

document.write(arrayBindings[0][arrayVars[0]].value)
您可以使用
brakets([])
dot(.)
符号访问对象属性:

因此,
arrayBindings[0].s.value
arrayBindings[0]['s']['value']
返回相同的值
http://ss.ldm.io/

现在,在两个阵列上动态循环:

for (i = 0; i < arrayBindings.length; i++) {
    for (j = 0; j < arrayVars.length; j++) {
        document.write(arrayBindings[i][arrayVars[j]].value);
    }
}
for(i=0;i