Referencing a javascript object literal array

后端 未结 5 1863
旧时难觅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:40

    The structure:

    var cars = [
        { name: 'Honda', models: [
                    { name: 'Accord', features: ['2dr', '4dr'] },
                    { name: 'CRV', features: ['2dr', 'Hatchback'] },
                    { name: 'Pilot', features: ['base', 'superDuper'] }
            ]},
    
        { name: 'Toyota', models: [
                    { name: 'Prius', features: ['green', 'superGreen'] },
                    { name: 'Camry', features: ['sporty', 'square'] },
                    { name: 'Corolla', features: ['cheap', 'superFly'] }
            ]}
    ];
    

    I wrote about the traversal and everything else here.

提交回复
热议问题