Javascript 嵌套数组中的Postman测试数组

Javascript 嵌套数组中的Postman测试数组,javascript,arrays,json,api,postman,Javascript,Arrays,Json,Api,Postman,我试图将断言放入postman数组中。我试图在数组中检索数组,但它有错误 如有任何建议,将不胜感激 { "meta": { "code": 200 }, "data": [ [ { "_index": "test", "_type": "test", "_id": "sdgsdfg", "_version": 1, "_shards": { "total":

我试图将断言放入postman数组中。我试图在数组中检索数组,但它有错误

如有任何建议,将不胜感激

{
  "meta": {
    "code": 200
  },
  "data": [
    [
      {
        "_index": "test",
        "_type": "test",
        "_id": "sdgsdfg",
        "_version": 1,
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "created": true
      },
      {
        "_index": "test",
        "_type": "test",
        "_id": "test",
        "_version": 1,
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "created": true
      },

    ]
  ]
}
到目前为止,我已经尝试过这个,但它给出了错误

var jsonData = JSON.parse(responseBody);

pm.test("Checking Success Response on Service", function () {
    pm.response.to.have.status(201);
});

for(var i=0; i< jsonData.data.length ;i++){

    for(var j=0; j< jsonData.data[i].length ;j++){
        console.log(jsonData.data[i].j._index);
    }
}
var jsonData=JSON.parse(responseBody);
测试(“检查服务的成功响应”,功能(){
pm.response.to.have.status(201);
});
对于(var i=0;i
评估测试脚本时出错:TypeError:无法读取未定义的属性“\u index”


请告诉我可以做什么。

您可以使用更基本的方法将这些值记录到控制台:

jsonData.data.forEach(dataItem => {
    dataItem.forEach(item => {
        console.log(item._index)
    })
})

这只是在数据数组上循环,然后在嵌套数组中循环。

嵌套数组因此
jsonData.data[i][j]。\u index
工作正常。但我不明白这里的逻辑,这里有第二个数组,在第一个数组里面。它也有全部单独的对象。
jsonData.data[i].j._index
当你说
j
时,它从字面上理解
j
。你需要说
[j]
,这样它就可以计算出j的值,然后搜索数组。你是说它的工作原理和矩阵一样吗?