Referencing a javascript object literal array

后端 未结 5 1878
旧时难觅i
旧时难觅i 2021-02-08 22:57

How would you reference the models (Accord, CRV, Prius, etc) in this structure? Is this a bad structure to be able to extract the makes...then use a make to get the models...th

5条回答
  •  旧巷少年郎
    2021-02-08 23:33

    You can traverse models with this code:

    for (var i = 0, carslen = cars.length; i < carslen; i++) {
        for (var j = 0, modelslen = cars[i].models.length; j < modelslen; j++) {
            // do something with cars[i].models[j]
        }
    }
    

    but I agree with Olliej about changing the structure of your JSON to his format.

提交回复
热议问题