通过JSON数组的Javascript循环

通过JSON数组的Javascript循环,javascript,json,Javascript,Json,我试图通过一个JSON对象循环,并在遇到问题时喋喋不休地说出宾果的值 {"testList":[{"number":"107832","secondList":[{"thirdList":[{"blah":"11111","blah2":"222222"}],"bingo":"0000"}]}]} 它是“secondList”的一部分,我只是不知道如何在没有嵌套循环的情况下访问 for(var i=0;data.testList.length<1;i++){ var fooOb

我试图通过一个JSON对象循环,并在遇到问题时喋喋不休地说出宾果的值

{"testList":[{"number":"107832","secondList":[{"thirdList":[{"blah":"11111","blah2":"222222"}],"bingo":"0000"}]}]}
它是“secondList”的一部分,我只是不知道如何在没有嵌套循环的情况下访问

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

    var fooObject = { 


            "number": data.testList[i].number,
            "bingo": <<<-----How to get this value???


    };

data.testList[i].secondList[0]。宾果就是您想要的。

此对象中的所有数组的长度都是1。如果总是这样,那么您就不必在它们之间循环:

fooObject = {
    "number" : data.testList[0].number,
    "bingo" : data.testList[0].secondList[0].bingo
};
如果数组中有多个项并且需要循环,那么也只需要在secondlist中循环。在for循环中:

for (var j = 0; data.testList[i].secondList.length < 1; i++) {
    fooObject.bingo = data.testList[i].secondList[j].bingo;
}

这就是您需要的:

console.log( json.testList[0].secondList[0].bingo)

data.testList[i].secondList[0]。宾果会这样做